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

📄 main.java

📁 在j2me中如何实现短信的发送和接受
💻 JAVA
字号:
package main;

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

public class Main extends Canvas implements Runnable {

	public Image img_logo1, img_logo2, img_logo3, img_logo4, img_logo5,
			img_about, img_bg;

	public static int stateloadingX = 0; // 进度条的X坐标

	public Image img_menu = null;

	public static int logo_time = 500; // 1000为一秒

	private final static int stateloading = 1; // 进度条

	private final static int stateMenu = 2; // 菜单

	private final static int stateAbout = 3; // 关于

	private final static int stateHelp = 4; // 帮助

	private final static int stateStudent = 5; // 学生号码

	private static int currentState = 0; // 当前状态

	private final static int sonyWidth = 176; // sonyEricsson-K550屏幕宽

	private final static int sonyHeight = 220; // sonyEricsson-K550屏幕高

	private static String[] strMenu = { "学生号码", "临时锁定", "日程安排", "锁定解锁 ",
			"在线升级 ", "帮助", "关于" };

	private static int selectedRow = 0; // 当前选中的行

	private static int selectedRowX = 20;
	
	public static String mobile="";

	Midlet midlet = null;

	Command cmdBack = null;

	public Main(MIDlet m) {
		try {
			// this.setFullScreenMode(true);
			midlet = (Midlet) m;

			img_logo1 = Image.createImage("/logo1.png");
			img_logo2 = Image.createImage("/logo2.png");
			img_logo3 = Image.createImage("/logo3.png");
			img_logo4 = Image.createImage("/logo4.png");
			img_logo5 = Image.createImage("/logo5.png");
			img_bg = Image.createImage("/imagebg2.png");

			Thread thread = new Thread(this);
			thread.start();

			currentState = stateloading;  // 一开始就读取进度条
			Display.getDisplay(m).setCurrent(this);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	protected void paint(Graphics g) {
		try {
			// 进度条
			if (currentState == stateloading) {

				// 清屏
				g.setColor(255, 255, 255);
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				
                //画图片
				if (logo_time == 500)
					g.drawImage(img_logo1, 0, 0, 0);
				if (logo_time == 1000)
					g.drawImage(img_logo2, 0, 0, 0);
				if (logo_time == 1500)
					g.drawImage(img_logo3, 0, 0, 0);
				if (logo_time == 2000)
					g.drawImage(img_logo4, 0, 0, 0);
				if (logo_time == 2500)
					g.drawImage(img_logo5, 0, 0, 0);
				
                //画进度条边框
				g.setColor(0, 0, 0);
				g.drawRect((this.getWidth() - 150) / 2, 195, 150, 10);
				//画进度条的实心条
				g.setColor(0, 255, 0);
				g.fillRect((this.getWidth() - 150) / 2, 195, stateloadingX * 15,
						10);
				//写进度条的百分比
				g.setColor(0, 0, 0);
				g.drawString(String.valueOf(stateloadingX * 10) + "%", 75, 192,
						0);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			// 菜单
			if (currentState == stateMenu) {

				// 清屏
				g.setColor(255, 255, 255);
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
                
				//背景图片
				g.drawImage(img_bg, 0, 0, 0);

				//写字(菜单)
				for (int i = 0; i < strMenu.length; i++) {
					if (i == selectedRow) {
						g.setColor(246, 247, 171);
						g.fillRect((this.getWidth() - 80) / 2, (i + 1) * 25, 80,
								20);
						g.setColor(255, 0, 0);
						g.drawString(strMenu[i], this.getWidth() / 2,
								(i + 1) * 25, Graphics.HCENTER | Graphics.TOP);

					} else {
						g.setColor(0, 0, 0);
						g.drawString(strMenu[i], this.getWidth() / 2,
								(i + 1) * 25, Graphics.HCENTER | Graphics.TOP);
					}
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			// 关于
			if (currentState == stateAbout) {
				g.setColor(255, 255, 255);
				g.fillRect(0, 0, this.getWidth(), this.getHeight());

				g.drawImage(img_about, 0, 0, 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			// 帮助
			if (currentState == stateHelp) {

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void run() {

		while (true) {
			// 关于
			try {
				if (currentState == stateAbout) {
					repaint();
					continue;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			// 帮助
			try {
				if (currentState == stateHelp) {
					repaint();
					continue;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			// 进度条和图片变量
			try {
				if (currentState == stateloading) {
					logo_time = logo_time + 500;
					stateloadingX = stateloadingX + 1;
					if(stateloadingX==1)
					{
						mobile=RMS.load();
						System.out.println("load:"+mobile);
					}
					// System.out.println(logo_time);
					if (stateloadingX > 10) {
						// stateloadingX = 10;
						currentState = stateMenu;

					}
					if (logo_time > 2500) {
						logo_time = 2500;
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			repaint();

			try {
				Thread.sleep(200);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

	protected void keyPressed(int keyCode) {
		// 进度条
		if (currentState == stateloading) {
			return;
		}

		// 菜单
		try {
			if (currentState == stateMenu) {

				// 向下
				if (keyCode == -2 || keyCode == 56) {

					selectedRow = selectedRow + 1;
					if (selectedRow > strMenu.length - 1) {
						selectedRow = 0;
					}
				}

				// 向上
				if (keyCode == -1 || keyCode == 50) {

					selectedRow = selectedRow - 1;
					if (selectedRow < 0) {
						selectedRow = strMenu.length - 1;
					}
				}

				// 选中
				if (keyCode == -5) {
					if(selectedRow==0)
					{
						SetMobileForm setMobileForm=new SetMobileForm(midlet,this);
					}
					if (selectedRow == 6) {
						img_about = Image.createImage("/imgabout.png");
						currentState = stateAbout;
					}
				}

				// 退出
				if (keyCode == -7) {
					midlet.destroyApp(false);
					midlet.notifyDestroyed();
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 关于
		try {
			if (currentState == stateAbout) {
				if (keyCode == -7) {
					currentState = stateMenu;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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