public class Myframe extends Frame{
public void LaunchFrame(){
setSize(500,500);
setLocation(200,200);
setVisible(true);
Button b = new Button("开始");
b.setSize(10,10);
add(b);
new Threader().start();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
g.drawRect(100, 100, 300, 300);
}
class Threader extends Thread{
public void run(){
while(true){
repaint();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String args[]){
Myframe my = new Myframe();
my.LaunchFrame();
}
}