问题编码简单文字处理器 [英] Problem coding simple word processor

查看:73
本文介绍了问题编码简单文字处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的文字处理器。实际上找到了一个非常有用的教程,正在引导我完成它。我仍然需要做很多工作,但它为我开始奠定了坚实的基础。当我正在编写显示类时,我收到的错误是视频中的人没有得到。当我为按钮和滑块添加Action侦听器时,它给出了我的错误:AbstractButton类型中的方法addActionListener(ActionListener)不适用于

参数(显示)



以下是我所做的代码:



I'm working through making a simple word processor. Actually found a really helpful tutorial that is walking me through it. I'll still have to do quite a bit of work but it's giving me a solid foundation to start on. As I'm writing the display class, I'm getting an error that the guy in the video didn't get. When I add the Action listeners for the buttons and sliders, it gives me this error: The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the
arguments (Display)

Here is the code I've done:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextPane;

public class Display extends JPanel {
	private JTextPane textArea;
	private JButton saveButton;
	private JComboBox colorCombo;
	private JComboBox fontCombo;
	private JLabel processorLabel;
	private JSlider fontSize;

	// Create some arrays
	String[] colorItems = { "Red", "Blue", "Green", "Purple", "Orange", "Black" };
	String[] fontItems = { "Monospaced", "Serif", "Sans Serif" };

	public Display() {
		init();
	}

	public void init() {
		// Construct Components
		textArea = new JTextPane();
		saveButton = new JButton("Save");
		colorCombo = new JComboBox(colorItems);
		fontCombo = new JComboBox(fontItems);
		processorLabel = new JLabel("Charles' Word Processor");
		fontSize = new JSlider(10, 30);

		// Work with slider
		fontSize.setOrientation(JSlider.HORIZONTAL);
		fontSize.setMinorTickSpacing(1);
		fontSize.setMajorTickSpacing(5);
		fontSize.setPaintTicks(true);
		fontSize.setPaintLabels(true);

		// Make the text area look presentable
		textArea.setBackground(Color.LIGHT_GRAY);
		// textArea.setForeground(color);

		// Adjust size and layout
		setPreferredSize(new Dimension(817, 473));
		setLayout(null);

		// Add components
		add(textArea);
		add(saveButton);
		add(colorCombo);
		add(fontCombo);
		add(processorLabel);
		add(fontSize);

		// set boundaries
		textArea.setBounds(10, 10, 650, 450);
		saveButton.setBounds(670, 315, 140, 35);
		colorCombo.setBounds(670, 205, 140, 35);
		fontCombo.setBounds(670, 150, 140, 35);
		processorLabel.setBounds(670, 20, 140, 35);
		fontSize.setBounds(670, 95, 140, 49);

		// add action listeners
		saveButton.addActionListener(this);
		colorCombo.addActionListener(this);
		fontCombo.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {

	}
}





任何帮助将不胜感激。谢谢你们!



我尝试了什么:



我'我们尝试将this转换为动作监听器。没有工作



Any help would be greatly appreciated. Thank you guys!

What I have tried:

I've tried changing casting "this" to the action listener. Didn't work

推荐答案

好的,问题是我应该在类的顶部输入:

公共类显示扩展JPanel实现ActionListener {



这就是为什么当我在课堂上制作动作听众时它无法正常工作。
Okay so the problem was I should have typed at the top of the class:
public class Display extends JPanel implements ActionListener{

That's why it wasn't working when I made the action listeners later in the class.


这篇关于问题编码简单文字处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆