?? car.java
字號:
//Car.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;public class Car extends JApplet implements Runnable{ private Image spin; private int currentLocation; private Thread spirit; public Car() { } //applet初始化 public void init() { currentLocation=0; spin=getImage(getDocumentBase(),"image/car.gif"); } public void start(){ spirit=new Thread(this); spirit.start(); } public void paint(Graphics g){ g.drawImage(spin,currentLocation,30,this);//在當前位置處繪制圖片 currentLocation=(currentLocation+3)%400;//另圖片在顯示區域中不斷顯示 } public void stop(){ spirit=null; } public void run(){ while(spirit!=null) { repaint(); try{ spirit.sleep(200);//線程休眠200毫秒,即另圖片在當前位置停留200毫秒 } catch(InterruptedException e) { e.printStackTrace() ; } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -