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

📄 gameapplet.java

📁 how to make a game using java.
💻 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 + -