home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 1998 #2 / MACPEOPLE-1998-NO2.ISO / おまけ / ジャバジャバ工作教室 / 第6回 / MPPApplet6.java < prev   
Text File  |  1997-09-22  |  1KB  |  53 lines

  1. import java.awt.*;
  2. import java.util.Random;
  3.  
  4. public class MPPApplet6 extends java.applet.Applet {
  5.     
  6.     int XX,YY,X1,Y1,RX,RY;
  7.     Color myC;
  8.     Random myR;
  9.     
  10.     public void start() {
  11.         myR = new Random ();
  12.     }
  13.     
  14.     public void update (Graphics g) {
  15.         paint (g);
  16.     }
  17.  
  18.      public void paint (Graphics g) {
  19.          g.setColor (Color.black);
  20.          g.fillRect (0,0,400,300);
  21.         g.setColor (myC);
  22.         g.fillOval (XX,YY,RX,RY);
  23.     }
  24.  
  25.     public boolean mouseUp (Event evt,int x,int y) {
  26.         X1 = myR.nextInt () % 10;
  27.         Y1 = Math.abs (myR.nextInt ()) % 10 + 5;
  28.         RX = 10;
  29.         RY = 10;
  30.         myC = Color.red;
  31.         for (int i = 1; i<=20; i++) {
  32.             XX = 200 + (X1 * i);
  33.             YY = 300 - (Y1 * i);
  34.             repaint ();
  35.             try {Thread.sleep (50);}
  36.             catch (InterruptedException e) {}
  37.         }
  38.         for (int i = 1; i<=10; i++) {
  39.             myC = new Color (myR.nextInt());
  40.             RX = RX + 10;
  41.             RY = RY + 10;
  42.             XX = XX - 5;
  43.             YY = YY - 5;
  44.             repaint ();
  45.             try {Thread.sleep (50);}
  46.             catch (InterruptedException e) {}
  47.         }
  48.         XX = -1000;
  49.         YY = -1000;
  50.         repaint ();
  51.         return true;
  52.     }
  53. }