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

📄 main.java

📁 一个推箱子游戏
💻 JAVA
字号:
/*
*	Game name : 
*	Development date:
*	Author:	k7sem
*	
*
*	Main.class
*	function:	control midelt program's lifecircle,display logos
*/

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Main extends MIDlet
{
	Nutty n;
	Main main;
	Logo logo;
	/*constructor*/
	public Main()
	{
		
	}
	
	public void startApp()
	{
		main = this ; 
		logo = new Logo();
		Display.getDisplay(this).setCurrent(logo);

	}
	public void pauseApp()
	{
	}
	public void destroyApp(boolean un)
	{
	}

	public void show(boolean b)
	{
		if(b)
		{
			logo = null;
			n = new Nutty(main);
			Display.getDisplay(main).setCurrent(n);
			
			//System.out.println(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory());
		}else
		{
		}
	}

	/*exit game*/
	public void exitApp()
	{
		destroyApp(false);
		notifyDestroyed();
	}

	///////////////////////////////////////////////////////////////
	///////inner class		Display logo images///////////////////
	///////////////////////////////////////////////////////////////
	class Logo extends Canvas implements Runnable
	{
		/*logo images array*/
		private Image[] img = new Image[3];
		
		/*load flag*/
		private int error ; 
		
		/*control display*/
		private int counter;
		
		/*Thread reference*/
		private Thread t;

		/*Display area*/
		private int scrW = 128 ;
		private int scrH = 128 ; 

		/*Logo constructor*/
		Logo()
		{
			/*Full screen*/
			setFullScreenMode(true);
			
			/*load logo images*/
			error = loadImages(true);
			
			/*start thread*/
			t = new Thread(this);
			t.start();
		}
		/*
		*Function : Loads logo images
		*	
		*Parameter: b  true->load  false->unload
		*
		*return value:	0->complete -1->exception
		*/
		private int loadImages(boolean b)
		{
			if(b)
			{
				try
				{
					for(int i = 0 ; i < 3 ; i++)
						img[i] = Image.createImage("/logo/"+i+".png");

					return 0 ; 
				}catch(Exception e)
				{
					return -1 ;
				}
			}else
			{			
					for(int i = 0 ; i < 3 ; i++)
						img[i] = null;	
					
					return 0;
			}
		}

		/*Display logo images*/
		public void paint(Graphics g)
		{
			g.setColor(0xffffff);
			g.fillRect(0,0,scrW,scrH);

			if(error != -1)
			{

				if(counter < 3)				
					g.drawImage(img[counter],(scrW-img[counter].getWidth()) >> 1 , (scrH - img[counter].getHeight()) >> 1,0) ; 

				
			}else
			{
				g.setColor(0xff0000);
				g.drawString("Load logo error!",30,scrH >> 1,0);
			}

			
		}

		/*Control display time*/
		public void run()
		{
			for(;;)
			{
				if(error != -1)
				{
					
					try
					{
						t.sleep(1000L);
						repaint();
						serviceRepaints();
					}catch(InterruptedException ie)
					{
						ie.printStackTrace();
						break ; 
					}

					if(counter < 3)
						counter++;
					else
						break;
				}else
				{
					try
					{
						t.sleep(1000L);
					}catch(InterruptedException ie)
					{
						ie.printStackTrace();
						
					}
					break ; 
				}
			}
			loadImages(false);
			t = null;
			System.gc();
			main.show(true);
		}
	}
}

⌨️ 快捷键说明

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