正文

java GUI小程序2006-04-08 17:29:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sword2008/12112.html

分享到:

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){
  }
 }
}

阅读(5668) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册