zoukankan      html  css  js  c++  java
  • java GUI小程序

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

  • 相关阅读:
    C# 之 HttpRequest 类
    C# 之 日常问题积累(一)
    DataGrid前台数据绑定技巧
    [转]C,C++开源项目中的100个Bugs
    10行Python代码解决约瑟夫环(模拟)
    基于ASP.NET的comet简单实现 http长连接,IAsyncResult
    架构设计分享之权限系统(看图说话)
    内核request_mem_region 和 ioremap的理解
    【调侃】IOC前世今生 工厂模式 反射 依赖倒置
    ecos内核概览--bakayi译
  • 原文地址:https://www.cnblogs.com/javaitpx/p/2760268.html
Copyright © 2011-2022 走看看