E
elingtse
Hi all,
I have problem to call the ActionListener but have no idea what is
going wrong, Please help. Thankyou.
When compile, the error message show :
-----------------------------------------------------------
C:\>javac TestEditorFrame.java
..\EditorFrame.java:7: cannot resolve symbol
symbol : class ActionListener
location: class EditorFrame
public class EditorFrame extends JFrame implements ActionListener{
^
..\EditorFrame.java:45: cannot resolve symbol
symbol : class ActionEvent
location: class EditorFrame
public void actionPerformed(ActionEvent ae){
^
..\EditorFrame.java:40: addActionListener(java.awt.event.ActionListener)
in javax
..swing.AbstractButton cannot be applied to (javax.swing.JMenuItem)
itemSave.addActionListener(itemSave);
^
3 errors
Class EditorFrame
---------------------------
import java.awt.*;
import javax.swing.*;
public class EditorFrame extends JFrame implements ActionListener{
//Attribute
private JTextArea textArea;
private JMenuBar menubar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenuItem itemSave = new JMenuItem("Save");
//constructor
public EditorFrame(){
Container contentPane = getContentPane();
String content = ("This is a text.\nSecond Line.");
textArea = new JTextArea(content, 3, 20);
setJMenuBar(menubar);
menubar.add(fileMenu);
fileMenu.add(itemSave);
contentPane.add(textArea);
itemSave.addActionListener(this);
}
//Action Listener Method
public void actionPerformed(ActionEvent ae){
System.out.println("ok");
}
}
Class TestEditorFrame
---------------------------------
import java.awt.*;
import javax.swing.*;
//Definition of class TestEditorFrame
public class TestEditorFrame extends JFrame {
//Main executive method
public static void main(String args[]){
//create an EditorFrame object
EditorFrame anEditor = new EditorFrame();
anEditor.setVisible(true);
//set when the close button is clicked, the application exits
anEditor.setDefaultCloseOperation(EXIT_ON_CLOSE);
//Set the GUI to its optimal size
anEditor.pack();
}
}
I have problem to call the ActionListener but have no idea what is
going wrong, Please help. Thankyou.
When compile, the error message show :
-----------------------------------------------------------
C:\>javac TestEditorFrame.java
..\EditorFrame.java:7: cannot resolve symbol
symbol : class ActionListener
location: class EditorFrame
public class EditorFrame extends JFrame implements ActionListener{
^
..\EditorFrame.java:45: cannot resolve symbol
symbol : class ActionEvent
location: class EditorFrame
public void actionPerformed(ActionEvent ae){
^
..\EditorFrame.java:40: addActionListener(java.awt.event.ActionListener)
in javax
..swing.AbstractButton cannot be applied to (javax.swing.JMenuItem)
itemSave.addActionListener(itemSave);
^
3 errors
Class EditorFrame
---------------------------
import java.awt.*;
import javax.swing.*;
public class EditorFrame extends JFrame implements ActionListener{
//Attribute
private JTextArea textArea;
private JMenuBar menubar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenuItem itemSave = new JMenuItem("Save");
//constructor
public EditorFrame(){
Container contentPane = getContentPane();
String content = ("This is a text.\nSecond Line.");
textArea = new JTextArea(content, 3, 20);
setJMenuBar(menubar);
menubar.add(fileMenu);
fileMenu.add(itemSave);
contentPane.add(textArea);
itemSave.addActionListener(this);
}
//Action Listener Method
public void actionPerformed(ActionEvent ae){
System.out.println("ok");
}
}
Class TestEditorFrame
---------------------------------
import java.awt.*;
import javax.swing.*;
//Definition of class TestEditorFrame
public class TestEditorFrame extends JFrame {
//Main executive method
public static void main(String args[]){
//create an EditorFrame object
EditorFrame anEditor = new EditorFrame();
anEditor.setVisible(true);
//set when the close button is clicked, the application exits
anEditor.setDefaultCloseOperation(EXIT_ON_CLOSE);
//Set the GUI to its optimal size
anEditor.pack();
}
}