上代码:
package exit;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class exit {
Frame f = new Frame("test");
Button b1 = new Button("btn1");
public void init()
{
f.setLayout(null);
b1.setBounds(20,30,90,29);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}
});
f.add(b1);
f.setBounds(50,50,550,500);
f.setVisible(true);
}
public static void main(String[] args) {
new exit().init();
}
}
直接运行点击就可以退出。
阅读(937) | 评论(0) | 转发(0) |