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

📄 main.java

📁 日程安排 功能还不完善 似的 还得补充
💻 JAVA
字号:

import java.io.IOException;

import javax.microedition.lcdui.*;

public class Main extends Canvas implements Runnable {
	int screenwidth = 240;
	int screenheight = 289;
	int loadcount = 1;
	Thread thread = null;
	int currentstate = -1;
	final static int stateloading = 1;
	final static int statemenu = 2;
	final static int stateabout = 3;
	String[] menuStr = { "学生号码", "临时锁定", "日程安排", "帮助", "锁定解锁", "在线升级", "关于" };

	int currentmenuindex = 0;
	int startx = 50;
	Image img = null;
Image bufferImage=null;
Image currentImage=null;
Graphics bufferImageG=null;
Image menu=null;
Image imgSmallbg=null;
Image icon=null;
Midlet midlet=null;
public static String mobile="";
SetMobileForm s=null;
	public Main(Midlet midlet) {
		try {
			this.midlet=midlet;
			bufferImage=Image.createImage(240, 289);
			this.bufferImageG=this.bufferImage.getGraphics();
			this.icon=Image.createImage("/cplogo.png");
			this.imgSmallbg=Image.createImage("/smallBG.png");
			this.currentImage=Image.createImage("/bg1.png");
			this.menu=Image.createImage("/Menu.png");
			this.img = Image.createImage("/abort.png");
			currentstate = stateloading;
			thread = new Thread(this);
			thread.start();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
int threadcount=0;
sound sound=Factory.creater();
	public void run() {
		try {
			
			while (true) {
				
				
				
				
				
				threadcount++;
				//System.out.println("threadcount:"+threadcount);
				if(this.currentstate==stateabout)
				{
					
				 	repaint();
					thread.sleep(100);
					continue;
					
				}
				if (this.currentstate == statemenu) {
					startx = startx + 5;
					
					if (startx >= this.screenwidth / 2) {
						startx = this.screenwidth / 2;
					}
				}
				if (this.currentstate == stateloading) {
					loadcount = loadcount + 1;
					if(loadcount==2)
					{
						mobile=Record.loadrs();
					}
					if(loadcount==3)
					{
						sound.load();
					}
					if (loadcount > 15) {
						currentstate = statemenu;
						//System.out.println(currentstate);

					}
				}
             
				
				
				repaint();
//				this.serviceRepaints();
				thread.sleep(100);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
int paintcount=0;
	protected void paint(Graphics g) {
		try {
			paintcount++;
			//System.out.println("paintcount:"+paintcount);
			
			Font font=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
			bufferImageG.setFont(font);
			bufferImageG.setColor(255, 255, 255);
			bufferImageG.fillRect(0, 0, screenwidth, screenheight);
			bufferImageG.setColor(255, 0, 0);
			if (currentstate == stateloading) {
				
				bufferImageG.setColor(255, 0, 0);
				int rectwidth = 150;
				int rectheight = 10;
				int x = (screenwidth - 150) / 2;
				int y = 200;
				bufferImageG.drawImage(this.icon, 100, 50, Graphics.HCENTER|Graphics.TOP);
				bufferImageG.drawRect(x, y, rectwidth, rectheight);
				bufferImageG.fillRect(x, y, loadcount * 10, rectheight);
			}
			if (currentstate == statemenu) {
				
				
				for(int row=0;row<15;row++)
				{
					for(int col=0;col<20;col++)
					{
					
						bufferImageG.drawImage(imgSmallbg, col*14, row*20, 0);
					}
				}
				
				int x = this.screenwidth / 2;
				bufferImageG.setColor(128, 128, 128);
				bufferImageG.fillRect(x - 50, this.currentmenuindex * 30 + 50, 100, 25);
				bufferImageG.setColor(255, 0, 0);
				bufferImageG.drawImage(menu,  screenwidth/2, 50, Graphics.HCENTER | Graphics.TOP);
				for (int i = 0; i < menuStr.length; i++) {
					
					if (i == this.currentmenuindex) {
						bufferImageG.drawImage(currentImage, screenwidth/2, 50+i*30, Graphics.HCENTER | Graphics.TOP);
						bufferImageG.drawString(menuStr[i], this.startx, 50 + i * 30,
								Graphics.HCENTER | Graphics.TOP);
						
					} else {
						bufferImageG.drawString(menuStr[i], x, 50 + i * 30,
								Graphics.HCENTER | Graphics.TOP);
					}
				}
				
				bufferImageG.drawString("选择", 0, 289, Graphics.LEFT|Graphics.BOTTOM);
				
			}
			if (currentstate == stateabout) {
				//g.setClip(10, 10, 50, 50);
			
				bufferImageG.drawImage(this.img, 0, 0, 0);
				bufferImageG.drawString("退出",240, 289, Graphics.RIGHT|Graphics.BOTTOM);
			}
		
			g.drawImage(this.bufferImage, 0, 0, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
//sound1 sound1=new sound1();
	//sound2 sound2=new sound2();
	
	protected void keyPressed(int key) {
		startx=50;
	
	
	if(this.currentstate==stateloading)
	{
		return;
	}
	
	if(this.currentstate==statemenu){
	switch (key) {
	case -2:
		//sound1.playSound(1);
//				sound2.playSound(2);
		sound.playsound(2);
		this.currentmenuindex++;
		if (this.currentmenuindex >= menuStr.length) {
			this.currentmenuindex = 0;
		}
		break;
	case -1:
		//sound1.playSound(1);
		//sound2.playSound(2);
		sound.playsound(2);
		this.currentmenuindex--;
		if (this.currentmenuindex < 0) {
			this.currentmenuindex = menuStr.length - 1;
		}
		break;
	case -5:if (this.currentmenuindex == 6) {
		
		this.currentstate = stateabout;
		//System.out.println(currentstate);
	}
	break;
	case -6:
		if(this.currentmenuindex==0)
		{
			SetMobileForm s=new SetMobileForm(midlet,this);
		}
		if (this.currentmenuindex == 6) {
			
			this.currentstate = stateabout;
			//System.out.println("currentstate"+currentstate);
		}
		break;
	}}

	if (this.currentstate == stateabout) {
		if (key == -7) {
			img = null;
			System.gc();
			this.currentstate = statemenu;
			System.out.println("this.currentstate"+this.currentstate);
		}
	}
	}
	
}

⌨️ 快捷键说明

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