import java.awt.*;
import java.awt.event.*;
public class MyFrameCanExit extends Frame implements ① {
public MyFrameCanExit(String str){
super(str);
}
public void windowClosing( ② e) {
System.exit(0);
}
public void windowClosed(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public static void main(String args[ ]){
MyFrameCanExit fr = new MyFrameCanExit("Hello !");
fr. ③ (fr); //注册窗口事件监听器。
fr. ④ (200,200);
fr.setVisible(true);
}
1. 阅读下面的程序MyAdd.java,填写划线部分的语句或注释,并写出程序执行结果。
public class MyAdd { //继承线程类
static int total = 10;
int n;
public MyAdd(int n){
this.n=n;
}
public void run() {
try{
sleep(n); //含义是:
total=total+n;
System.out.println(total);
}
catch(Exception e){
System.out.println(“EXCEPTION!”);
}
}
public static void main(String[] args) {
MyAdd t1 = new MyAdd(3000);
; //启动线程t1
}
}
墨色风雨
相关分类