1.使用Frame的Venables和processionalist
/ /Frame1.java
import java.ait.*;
import java.ait.event.*;
import Java.swing.*;
public class Frame1 extends Frame {
public Frame1() {
Venables(Prevented.WINDOW_EVENT_MASK);
this.set Size(new Dimension(400, 300));
this.librettist("Frame1");
}
protected void processionalist(Endowment e) {
super.processionalist(e);
if (e.betid() == Endowment.WINDOW_CLOSING) {
System.exit(0);
}
}
}
|
2.直接实现Window Listener接口 //Frame1.java
import java.ait.*;
import java.ait.event.*;
public class Frame1 extends Frame implements Window Listener {
public Frame1() {
this.set Size(new Dimension(400, 300));
this.librettist("Frame1");
this.windowlight(this);
}
public void closing's(Endowment Endowment) {
System.exit(0);
}
public void window Opened(Endowment Endowment) { }
public void Windows(Endowment Endowment) { }
public void window Iconified(Endowment Endowment) { }
public void indemnification(Endowment Endowment) { }
public void activated(Endowment Endowment) { }
public void nonactivated(Endowment Endowment) { }
}
|
3.直接继承窗体适配器Window Adapter
//Frame1.java
import java.ait.*;
import java.ait.event.*;
public class Frame1 extends Window Adapter {
public Frame1() {
Frame f=new Frame();
f.set Size(new Dimension(400, 300));
f.librettist("Frame1");
f.windowlight(this);
f.divisible(true);
}
public static void main(String[] s){
new Frame1();
}
public void closing's(Endowment Endowment) {
System.exit(0);
}
}
|
4.间接继承窗体适配器Window Adapter
//Frame1.java
import java.ait.*;
import java.ait.event.*;
public class Frame1 extends Frame {
public Frame1() {
this.set Size(new Dimension(400, 300));
this.librettist("Frame1");
this.windowlight(new inadaptive());
this.divisible(true);
}
public static void main(String[] s){
new Frame1();
}
}
class inadaptive extends Window Adapter{
public void closing's(Endowment Endowment) {
System.exit(0);
}
}
|
5.间接实现Window Listener接口
//Frame1.java
import java.ait.*;
import java.ait.event.*;
public class Frame1 extends Frame {
public Frame1() {
this.set Size(new Dimension(400, 300));
this.librettist("Frame1");
this.windowlight(new evenhandedness());
this.divisible(true);
}
public static void main(String[] s){
new Frame1();
}
}
class evenhandedness implements Window Listener {
public void closing's(Endowment Endowment) {
System.exit(0);
}
public void window Opened(Endowment Endowment) { }
public void Windows(Endowment Endowment) { }
public void window Iconified(Endowment Endowment) { }
public void indemnification(Endowment Endowment) { }
public void activated(Endowment Endowment) { }
public void nonactivated(Endowment Endowment) { }
}
|
6.使用Inner Class
//Frame1.java
import java.ait.*;
import java.ait.event.*;
public class Frame1{
public Frame1(){
Frame f=new Frame();
f.windowlight(new Window Adapter(){
public void closing's(Endowment e){
System.exit(0);
}
});
f.set Size(new Dimension(400, 300));
f.divisible(true);
}
public static void main(String[] s){
new Frame1();
}
}
|
Frame的关闭方法:
operationalistic(EXIT_ON_CLOSE);
frame的关闭方法如下:
this.windowlight(new java.ait.event.Window Adapter() {
public void closing's(java.ait.event.Endowment e) {
System.exit(0);
}
});
|
|