java GUI小程序

论坛 期权论坛 脚本     
匿名技术用户   2021-1-1 20:23   517   0

import java.awt.*;
import javax.swing.*;

public class ColorAndLine extends JFrame{
public ColorAndLine(){
super("using color and line");
setSize(800,400);
setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
while(true)
{//System.out.print((int)(Math.random()*100));
g.setColor(new Color((int)(Math.random()*250),(int)(Math.random()*250),(int)(Math.random()*250)));
g.drawLine((int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*100),(int)(Math.random()*100));
repaint();
}
}
public static void main(String args[]){
ColorAndLine application=new ColorAndLine();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

修改

import java.awt.*;
import javax.swing.*;

public class ColorAndLine extends JFrame{
static int i=0;
public ColorAndLine(){
super("using color and line");
setSize(800,400);
setVisible(true);
}
public void paint(Graphics g){

// Gui gui=new Gui();
super.paint(g);

while(i<999999999)
{//System.out.print((int)(Math.random()*100));
g.setColor(new Color((int)(Math.random()*250),(int)(Math.random()*250),(int)(Math.random()*250)));
g.drawLine((int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000));
repaint();
Gui gui=new Gui();
gui.start();
i++;
}
}
public static void main(String args[]){

ColorAndLine application=new ColorAndLine();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

class Gui extends Thread{
public Gui(){
}
public void run(){
try{Thread.sleep(999999999);

}
catch(Exception e){
}
}
}

转载于:https://www.cnblogs.com/javaitpx/archive/2012/11/08/2760268.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP