我的Java小程序在编译时出现问题,请指教(本人初学者)
源程序如下:importjava.awt.*;importjava.awt.event.*;publicclassTestAddListenerimplementsAct...
源程序如下:
import java.awt.*;
import java.awt.event.*;
public class TestAddListener implements ActionListener,WindowListener {
Frame f;
Button b;
public void create() {
f=new Frame("Add Listeners");
b=new Button("press me");
b.addActionListener(this);
b.addWindowListener(this);
f.add(b,"North");
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String args[]) {
TestAddListener ta=new TestAddListener();
ta.create();
}
public void actionPerformed(ActionEvent e) {
System.out.println("the Button is pressed");
}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
编译时出现如下错误:
TestAddListener.java:10: 找不到符号
符号: 方法 addWindowListener(TestAddListener)
位置: 类 java.awt.Button
b.addWindowListener(this);
^
1 错误
我看了很久找不到问题所在,望各位前辈指点,多谢! 展开
import java.awt.*;
import java.awt.event.*;
public class TestAddListener implements ActionListener,WindowListener {
Frame f;
Button b;
public void create() {
f=new Frame("Add Listeners");
b=new Button("press me");
b.addActionListener(this);
b.addWindowListener(this);
f.add(b,"North");
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String args[]) {
TestAddListener ta=new TestAddListener();
ta.create();
}
public void actionPerformed(ActionEvent e) {
System.out.println("the Button is pressed");
}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
编译时出现如下错误:
TestAddListener.java:10: 找不到符号
符号: 方法 addWindowListener(TestAddListener)
位置: 类 java.awt.Button
b.addWindowListener(this);
^
1 错误
我看了很久找不到问题所在,望各位前辈指点,多谢! 展开
展开全部
为什么要给button加一个WindowListener...它只是一个按钮而已...
应该是f.addWindowListener吧..
应该是f.addWindowListener吧..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
button要加也是ActionEvent()吧!这部分都没怎么学!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
b是一个按钮类,没有这个方法addWindowListener();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询