randompic.java~4~

来自「Jbuilder100个例子 都是经典例子 对大家学习Jbuilder非常有帮助」· JAVA~4~ 代码 · 共 91 行

JAVA~4~
91
字号
package untitled2;import java.awt.*;import java.awt.event.*;import java.applet.*;public class randompic extends java.applet.Applet implements Runnable {  boolean isStandalone = false;  Thread runner = null;  Color mycolor;  int ndraw;  /**Get a parameter value*/  public String getParameter(String key, String def) {    return isStandalone ? System.getProperty(key, def) :      (getParameter(key) != null ? getParameter(key) : def);  }  /**Construct the applet*/  public randompic() {  }  /**Initialize the applet*/  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  /**Component initialization*/  private void jbInit() throws Exception {  }  /**Get Applet information*/  public String getAppletInfo() {    return "Applet Information";  }  /**Get parameter info*/  public String[][] getParameterInfo() {    return null;  }  public void start(){     if(runner==null){        runner=new Thread(this);        runner.start();     }  }  public void stop(){     if(runner!=null){         runner.stop();         runner=null;     }  }  public int draw(){     ndraw = (int)(4 * Math.random());     return ndraw;  }  public void run(){      while(true){        repaint();        try{           Thread.sleep(500); }        catch(InterruptedException e){}      }   }   public void paint(Graphics g){      int x = (int)(300 * Math.random());      int y = (int)(300 * Math.random());      int r = (int)(255 * Math.random());      int g1 = (int)(255 * Math.random());      int b = (int)(255 * Math.random());      mycolor = new Color(r,g1,b);      g.setColor(mycolor);      switch (draw()){          case 0:              g.fillOval(x,y,20,20);          case 1:              g.fillRect(x,y,20,20);          case 2:              g.fillRoundRect(x,y,20,20,10,10);          case 3:              g.fillOval(x,y,20,40);       }   }   public void update(Graphics g){      paint(g);   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?