Applet with Runnable Interface
import java.applet.Applet;
import java.awt.*;
import java.util.Random;
public class MyApplet extends Applet implements Runnable {
int x=40, y=40;
Color mycolor = new Color(0,255,255);
public void init() {
}
public void start()
{
Thread myt = new Thread(this);
myt.start();
}
public void update(Graphics g) {
g.setColor(mycolor);
g.fillOval(x,y,60,60);
}
public void run() {
Random myrno = new Random();
//for (int i=0; ; i++) {
while (true) {
try {
mycolor = new Color(myrno.nextInt(255),myrno.nextInt(255),myrno.nextInt(255));
x = myrno.nextInt(300);
y = myrno.nextInt(400);
Thread.sleep(1000);
repaint();
}
catch (Exception e)
{
}
}
}
}
import java.awt.*;
import java.util.Random;
public class MyApplet extends Applet implements Runnable {
int x=40, y=40;
Color mycolor = new Color(0,255,255);
public void init() {
}
public void start()
{
Thread myt = new Thread(this);
myt.start();
}
public void update(Graphics g) {
g.setColor(mycolor);
g.fillOval(x,y,60,60);
}
public void run() {
Random myrno = new Random();
//for (int i=0; ; i++) {
while (true) {
try {
mycolor = new Color(myrno.nextInt(255),myrno.nextInt(255),myrno.nextInt(255));
x = myrno.nextInt(300);
y = myrno.nextInt(400);
Thread.sleep(1000);
repaint();
}
catch (Exception e)
{
}
}
}
}
Comments
Post a Comment