1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/* Draw Dots at Random Locations in an Applet Example This Java example shows draw dots at random locations at specified interval using Java Thread and Applet classes. */ import java.applet.Applet; import java.awt.Dimension; import java.awt.Graphics; /* <applet code = "DrawDotsAtRandomLocationsExample" width = 500 height = 300> </applet> */ public class DrawDotsAtRandomLocationsExample extends Applet implements Runnable{ Thread t; public void init(){ //start new Thread t = new Thread(this); t.start(); } public void run(){ try{ while(true){ // Request repaint repaint(); Thread.sleep(200); } } catch(Exception e){ } } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ Dimension d = getSize(); int x = (int)(Math.random() * d.width); int y = (int)(Math.random() * d.height); g.fillRect(x,y,2,2); } } |
thnx
thnx very much
tnx