eventex.java

来自「how to make a game using java.」· Java 代码 · 共 62 行

JAVA
62
字号
// EventEx.java
// [Imperial Snowman Soft]

import java.awt.*;
import java.applet.*;
import GameLib.*;

public class EventEx extends GameApplet
{

  Gfx gfx;	 //The GAMELIB - Graphix class (double-buffering)
  int lastkey, x, y;

  public void init()
  {
    int speed = Integer.parseInt(getParameter("speed"));
    if(speed > 99) speed = 99;
    setSleepTime(100-speed);

    gfx = new Gfx(this, new Color(0,0,0));
  }

  public void paint(Graphics g)
  {
	      gfx.cls();
	      gfx.setColor(200,200,0);
	      gfx.drawString("LastKey: " + lastkey,10,10);
	      gfx.drawString("Mouse x,y: " + x + ", " + y,10,20);
 	      gfx.refresh();
  }

  public void game(int id)
  {
	switch(id)	
	{
		case 1:	//game(1) is called before the Applet sleeps
		{
			repaint();
		        break;
		}
		
		case 2:	//game(2) is called after the thread had slept.
		{
			break;
		}
	}
  }

   public boolean mouseMove(Event e, int x, int y)
   {
	this.x = x;
	this.y = y;
	return true;
   }

  public boolean keyDown(Event e, int key)
  {
	lastkey = key;
	return true;
  }
}

⌨️ 快捷键说明

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