当前位置: 代码迷 >> Java相关 >> [求助]java程序
  详细解决方案

[求助]java程序

热度:316   发布时间:2007-10-14 22:26:02.0
[求助]java程序
import java.awt.*;
import java.awt.event;
public class CalculatorFrame extends Frame implements ActionListener{
private TextField text;
private Button button_1,button_2,button_plus,button_cancel;
public CalculatorFrame(){
super("计算");
this.setSize(320,120);
this.setBackground(Color.LIGHT_GRAY);
this.setLocation(300,240);
this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));

text=new TextField(40);
text.setEditable(false);
this.add(text);

button_1=new Button("1");
button_2=new Button("2");
button_plus=new Button("+");
button_cancel=new Button("c");
this.add(button_1);
this.add(button_2);
this.add(button_plus);
this.add(button_cancel);
button_1.addActionListener(this);
button_2.addActionListener(this);
button_plus.addActionListener(this);
button_cancel.addActionListener(new WinClose());

this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button_cancel)
text.setText("");
}
public static void main(String[] args){
new CalculatorFrame();
}
}
class WinClose implements WindowListener{
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowOpened(WindowEvent e){ }
public void windowActivated(WindowEvent e){ }
public void windowDeactivated(WindowEvent e){ }
public void windowClosed(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
}
在程序运行时出现以下提示
CalculatorFrame.java:2: 找不到符号
符号: 类 event
位置: 软件包 java.awt
import java.awt.event;
^
CalculatorFrame.java:3: 找不到符号
符号: 类 ActionListener
public class CalculatorFrame extends Frame implements ActionListener{
^
CalculatorFrame.java:32: 找不到符号
符号: 类 ActionEvent
位置: 类 CalculatorFrame
public void actionPerformed(ActionEvent e){
^
CalculatorFrame.java:40: 找不到符号
符号: 类 WindowListener
class WinClose implements WindowListener{
^
CalculatorFrame.java:41: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowClosing(WindowEvent e){
^
CalculatorFrame.java:44: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowOpened(WindowEvent e){ }
^
CalculatorFrame.java:45: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowActivated(WindowEvent e){ }
^
CalculatorFrame.java:46: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowDeactivated(WindowEvent e){ }
^
CalculatorFrame.java:47: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowClosed(WindowEvent e){ }
^
CalculatorFrame.java:48: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowIconified(WindowEvent e){ }
^
CalculatorFrame.java:49: 找不到符号
符号: 类 WindowEvent
位置: 类 WinClose
public void windowDeiconified(WindowEvent e){ }
^
CalculatorFrame.java:25: 无法将 java.awt.Button 中的 addActionListener(java.awt.event.ActionListener) 应用于 (CalculatorFrame)
button_1.addActionListener(this);
^
CalculatorFrame.java:26: 无法将 java.awt.Button 中的 addActionListener(java.awt.event.ActionListener) 应用于 (CalculatorFrame)
button_2.addActionListener(this);
^
CalculatorFrame.java:27: 无法将 java.awt.Button 中的 addActionListener(java.awt.event.ActionListener) 应用于 (CalculatorFrame)
button_plus.addActionListener(this);
^
CalculatorFrame.java:28: 无法将 java.awt.Button 中的 addActionListener(java.awt.event.ActionListener) 应用于 (WinClose)
button_cancel.addActionListener(new WinClose());
^
15 错误
搜索更多相关的解决方案: java  

----------------解决方案--------------------------------------------------------
import java.awt.event;改成import java.awt.event.*;
并且button_cancel.addActionListener(new WinClose());也不行

----------------解决方案--------------------------------------------------------

多谢!


----------------解决方案--------------------------------------------------------
  相关解决方案