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;
String[] colorItems = { "Red", "Blue", "Green", "Purple", "Orange", "Black" };
String[] fontItems = { "Monospaced", "Serif", "Sans Serif" };
public Display() {
init();
}
public void init() {
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);
fontSize.setOrientation(JSlider.HORIZONTAL);
fontSize.setMinorTickSpacing(1);
fontSize.setMajorTickSpacing(5);
fontSize.setPaintTicks(true);
fontSize.setPaintLabels(true);
textArea.setBackground(Color.LIGHT_GRAY);
setPreferredSize(new Dimension(817, 473));
setLayout(null);
add(textArea);
add(saveButton);
add(colorCombo);
add(fontCombo);
add(processorLabel);
add(fontSize);
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);
saveButton.addActionListener(this);
colorCombo.addActionListener(this);
fontCombo.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
}
}
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