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

  • 相关阅读:
    玩4K必备知识:HDMI1.4、2.0、2.0a、2.0b接口参数对比【扫盲贴】
    Gradle配置最佳实践
    Android Studio 中安装 apk 被拆分成多个 slice,如何禁止?
    编译不同平台 设定
    编译找错
    Delphi 中内存映射对于大文件的使用
    linux——nmap端口扫描命令
    Android 使用 adb命令 远程安装apk
    插件编译 版本问题
    2019 opensuse linux Eclipse
  • 原文地址:https://www.cnblogs.com/javaitpx/p/2760268.html
Copyright © 2011-2022 走看看