- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package mygriphics;
- import java.awt.*;
- import java.awt.event.*;
- /**
- *
- * @author mdj
- */
- public class OvalDrawer extends Frame implements Runnable{
- private Color[] colors={Color.RED,Color.BLACK,Color.BLUE,Color.GREEN,Color.DARK_GRAY};
- private Color color;
- private int x=100,y=100,width=100,height=100;
- public OvalDrawer(String title){
- super(title);
- setSize(300,300);
- setVisible(true);
- new Thread(this).start();
- }
- public void run(){
- while(true){
- x=(int)(Math.random()*300);
- y=(int)(Math.random()*300);
- width=(int)(Math.random()*100);
- height=(int)(Math.random()*100);
- color=colors[(int)(Math.random()*colors.length-1)];
- repaint();
- try{
- Thread.sleep(400);
- }
- catch(InterruptedException e){
- throw new RuntimeException(e);
- }
- }
- }
- public void update(Graphics g){
- paint(g);
- }
- public void paint(Graphics g){
- g.setColor(color);
- g.fillOval(x, y, width, height);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- new OvalDrawer("paint");
- }
- }