菜鸟问问题>_<
我有一个button按钮“退出”,我想让它
用
setVisible(false);
dispose();
来退出程序。
这两个命令是窗口对象的。。按钮怎么得到窗口对象。。
请教ActionListemer里的命令如何写
public class myActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("退出"))
{
}
}
}
谢谢了。
问题点数:10、回复次数:2Top
1 楼aaa2003gf(珍惜 (MSN:aaa2003gf@hotmail.com))回复于 2006-02-11 23:36:29 得分 10
你的按钮对象不是建立在Frame的class里吗,你直接写this.dispose(),就OK啦啊.Top
2 楼lyf040230427(枫叶)回复于 2006-02-21 13:41:37 得分 0
JButton b = new JButton();
b.addActionListener(this);
public void actionPerformed(ActionEvent e){
if(e.getSource == b){
setVisible(false);
}
或者采用匿名内部类
b.addActionListener(new EventHandle(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equalsIgnoreCase("exit"))
setVisible(false);
}
});
Top




