📄 randompic.java~6~
字号:
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(200); } 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,10,10); case 1: g.fillRect(x,y,10,10); case 2: g.fillRoundRect(x,y,10,10,5,5); case 3: g.fillOval(x,y,10,20); } } public void update(Graphics g){ paint(g); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -