?? gameapplet.java
字號:
/**
*
* The GameApplet is used to create an Applet-Thread. It extends
* the Applet class and contains the Runnable interface.
* (C)2002 by [ISSoft]
*
**/
package GameLib;
import java.applet.*;
import java.awt.*;
abstract public class GameApplet extends Applet implements Runnable
{
// This is the main thread, used for ticks.
public Thread gameThread = null;
// The sleep time of the GameApplet
private long sleepTime= 50;
/* Initialize. */
public void init()
{
}
/* Start the thread. */
public void start()
{
if(gameThread == null)
{
gameThread = new Thread(this);
gameThread.start();
//gameThread.setPriority (Thread.MAX_PRIORITY);
}
}
/* Stop the thread. */
public void stop()
{
if (gameThread != null)
gameThread.stop (); //kill thread when applet is stopped
gameThread = null;
}
public void setSleepTime(long millis)
{
this.sleepTime = millis;
}
public void setSleepTime(int millis)
{
this.sleepTime = (long)millis;
}
public long getSleepTime ()
{
return this.sleepTime;
}
public void run()
{
while (gameThread != null)
{
game(1);
try
{
gameThread.sleep(getSleepTime());
}
catch(InterruptedException e)
{
gameException();
}
game(2);
}
gameThread = null;
}
public void game(int id) {}
public void gameException() {}
public void update(Graphics g)
{
paint(g);
}
public String getAppletInfo()
{
return ("The GameApplet, a class that creates an Thread from an Applet using the Applet class and the Runnable interface.");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -