button.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent ae ){
MyFrame.this.dispose();
System.exit(0);
...................大约这样
没测试过
public void actionPerformed( ActionEvent ae ){
MyFrame.this.dispose();
System.exit(0);
...................大约这样
没测试过
{
Button close;
public help()
{
super("A help example!!");
}
public void setup()
{
close=new Button("Close");
resize(200,100);
add(close);
show();
}
public boolean action(Event event,Object o)
{
if(event.id==Event.WINDOW_DEICONIFY||event.target==close)
{
hide();
dispose();
System.exit(1);
return true;
}
return true;
}
public static void main(String args[])
{
help a=new help();
a.setup();
}
}
import java.awt.*;
import java.awt.event.*;
public class T{
public static void main(String args[])
{
final JFrame frm = new JFrame();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(400,300);
JButton button = new JButton("Exit");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frm.dispose();
}
});
frm.getContentPane().setLayout(new FlowLayout());
frm.getContentPane().add(button);
frm.show();
}
}
import java.awt.*;
import java,awt.event.*;
public class mywindow extends Frame
{public void mywindow(String s)
{super(s);
setSize(100,100);
setColor(Color.white);
setVisible(true);
}
}
public class a extends Applet implements ActionListener
{mywindow window;
Botton b;
public void init();
{window=newmywindow("我的窗口");
b=newBotton;
window.add(b);
b.addActionListener(this);
}
public void ActionPerformed(ActionEvent e)
{if(e.getSouce==b)
{System.exit(0);
}
}
}