展开全部
import java.awt.Graphics;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import java.util.Random;
public class JFrameSimpleDraw extends JFrame {
boolean bStop=false;
private static final long serialVersionUID = 1L;
public JFrameSimpleDraw() {
super("JFrameSimpleDraw");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setBounds(100, 100, 450, 450);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
bStop=true;
}
});
}
Random rnd = new Random();
public void paint(Graphics g){
super.paint(g);
g.fillRect(0,0, getWidth(), getHeight());
for(int i=0; i<20; i++){
int x = rnd.nextInt(getWidth());
int y = rnd.nextInt(getHeight());
int rc=rnd.nextInt(0xff);
int gc=rnd.nextInt(0xff);
int bc=rnd.nextInt(0xff);
g.setColor(new Color(rc,gc,bc));
g.drawString("*", x, y);
if(bStop){
return;
}
try{
Thread.sleep(100);
}catch(Exception e){
}
}
int x = rnd.nextInt(getWidth());
int y = rnd.nextInt(100);
g.setColor(Color.white);
g.drawOval(x, y, 20, 20);
try{
Thread.sleep(4000);
}catch(Exception e){
}
this.repaint();
}
public static void main(String []args){
new JFrameSimpleDraw();
}
}
猛击关闭窗口的小e69da5e6ba9062616964757a686964616f31333332643932x来退出程序