?? example19_7.java
字號:
import java.awt.*;import java.awt.event.*;import java.applet.*;public class Example19_7 extends Applet implements Runnable{Thread 紅色球,蘭色球; Graphics redPen,bluePen;int t=0; public void init() { 紅色球=new Thread(this); 蘭色球=new Thread(this); redPen=getGraphics(); bluePen=getGraphics(); redPen.setColor(Color.red); bluePen.setColor(Color.blue); } public void start() {紅色球.start();蘭色球.start(); } public void run() { while(true) { t=t+1; if(Thread.currentThread()==紅色球) {if(t>100) t=0; redPen.clearRect(0,0,110,400); redPen.fillOval(50,(int)(1.0/2*t*9.8),5,5); try{紅色球.sleep(40);} catch(InterruptedException e){} } else if(Thread.currentThread()==蘭色球) {bluePen.clearRect(120,0,900,500); bluePen.fillOval(120+7*t,(int)(1.0/2*t*9.8),5,5); try{蘭色球.sleep(40);} catch(InterruptedException e){} } } } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -