⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spottest.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class SpotTest extends Applet {

  /* SpotTest                J M Bishop Aug 2000
   * ========
   *
   * Draws spots of different colours
   *
   * Illustrates simple threads
   */

    int mx, my;
    int radius = 10;
    int boardSize = 200;
    int change;

    public void init() {
      boardSize = getSize().width - 1;
      change = boardSize-radius;

      // creates and starts three threads
      new Spots(Color.red).start();
      new Spots(Color.blue).start();
      new Spots(Color.green).start();
    }


  class Spots extends Thread {

    Color colour;

    // the constructor records the thread's colour
	Spots(Color c) {
	  colour = c;
	}

    // a very simple run method
    public void run () {
      while (true) {
        draw();
        try {
          sleep (500); // millisecs
        }
        catch (InterruptedException e) {
        }
      }
    }

   public void draw() {
     Graphics g = getGraphics();
     g.setColor(colour);
     // calculate a new place for a spot
     // and draw it.
     mx = (int)(Math.random()*1000) % change;
     my = (int)(Math.random()*1000) % change;
     g.fillOval(mx, my, radius, radius);
  }
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -