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

📄 mainscreen.java

📁 PDA餐饮管理系统,在掌上电脑实现的,可以开台,点菜等多功能模块
💻 JAVA
字号:
package junwei;

import javax.microedition.lcdui.*;

import rms.Table;

/**
 * 主界面,图形化桌台显示
 * @author hong
 *
 */
public class MainScreen extends Canvas implements CommandListener {
	private static MainScreen instance;
	
	//图片
	private Image img_free = null;
	private Image img_use=null;
	private Image img_engage = null;
	private Image img_stop=null;
	private int imgHeight;
	private int imgWidth;
	
	//行数,列数
	private int rows;
	private int cols;
	private int curX=0;
	private int curY=0;
	//上下信息区高度
	final static int top=25;
	final static int bottom=40;
	private int left;
	
	//翻页
	private int tableCount=30;
	private int curPage=0;
	private int pages;
	private Table[][] cur_tables; //显示的桌台
	public Table[] all_tables;  //所有桌台
	
	private Command cmd_Login;
	private Command cmd_Table;
	private Command cmd_Dish;
	private Ticker ticker;

	synchronized public static MainScreen getInstance() {
		if (instance == null) {
			instance = new MainScreen();
		}
		return instance;
	}

	private MainScreen() {
		super();
		ticker=new Ticker("欢迎使用君威餐饮管理系统");
		this.setTicker(ticker);
		
		cmd_Login=new Command("登录", Command.ITEM, 1);
		cmd_Table=new Command("开换台>>", Command.ITEM, 1);
		cmd_Dish=new Command("点退菜>>", Command.ITEM, 2);
		initMenu();
		// 增加菜单
		addCommand(new Command("查询信息>>", Command.ITEM, 5));
		addCommand(new Command("数据下载", Command.ITEM, 6));
		addCommand(new Command("系统信息设置", Command.ITEM, 7));
		addCommand(new Command("刷新桌台", Command.EXIT, 2));
		addCommand(new Command("退出", Command.EXIT, 6));
		setCommandListener(this);

		try {
			img_free = Image.createImage("/picFree.png");
			img_use = Image.createImage("/picUse.png");
			img_engage = Image.createImage("/picEngage.png");
			img_stop = Image.createImage("/picStop.png");
			imgHeight = img_free.getHeight()+15;
			imgWidth = img_free.getWidth()+2;
		} catch (Exception e) {
			System.out.println("找不到图片!");
		}
		rows = (this.getHeight()-top-bottom) / imgHeight;
		cols = this.getWidth()/imgWidth;
		left=(this.getWidth()-cols*imgWidth)/2;
		
		cur_tables=new Table[cols][rows];
	}

    //初始化当前显示桌台
	public void initShowTable() {
		int m = rows * cols * curPage;

		for (int j = 0; j < rows; j++)
			for (int i = 0; i < cols; i++) {
				if (m < tableCount) 
					cur_tables[i][j] = all_tables[m++];
				else
					cur_tables[i][j] = null;
			}
	}
	
	/**
	 * 绘制一张桌台
	 */
	private void drawATable(Graphics g, int x, int y ) {
		
		if (cur_tables[x][y]==null)
			return;
		
		String s=cur_tables[x][y].getTableName();
		Image img=null;

        //选择图象
		switch (cur_tables[x][y].getStatus()){
		case Table.ST_free:
			img=img_free;
			break;
		case Table.ST_use:
			img=img_use;
			break;
		case Table.ST_engage:
			img=img_engage;
			break;
		case Table.ST_stop:
			img=img_stop;
		}
	
		g.drawImage(img, left+x * imgWidth+1, top+y * imgHeight+1, 20);
		int oldclipX = g.getClipX();
		int oldClipY = g.getClipY();
		int oldClipWidth = g.getClipWidth();
		int oldClipHeight = g.getClipHeight();
		g.setClip(left+x * imgWidth+2, top+y*imgHeight+imgHeight-14,imgWidth-4,13);
		int Strleft=(imgWidth-g.getFont().stringWidth(s))/2;
		if (Strleft<0) 
			Strleft=0;
		g.drawString(s, left+x * imgWidth+Strleft+2, top+y * imgHeight
				+ img_use.getHeight(), 20);
		g.setClip(oldclipX, oldClipY, oldClipWidth, oldClipHeight);

		
		//绘制选中框
		if ((curX==x)&&(curY==y)){
			g.setColor(255,0,0);
			g.drawRect(left+x * imgWidth, top+y * imgHeight, imgWidth, imgHeight);
			g.setColor(0,0,0);
		}
	}

	public void paint(Graphics g) {
        g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0, 0, 0);
		g.drawRect(2, 2, this.getWidth() - 5, this.getHeight() - 5);
		g.drawLine(2, top - 5, this.getWidth() - 4, top - 5);
		g.drawLine(2, this.getHeight() - bottom, this.getWidth() - 4, this
				.getHeight()-bottom);

		if (cur_tables[curX][curY] != null) {
			g.drawString("当前桌号:" + cur_tables[curX][curY].getTableNo(), 10, 3,
					20);
			g.drawString("状态:" + cur_tables[curX][curY].getStatusName(), 100,
					3, 20);
		}
		g.drawString((curPage + 1) + "/" + pages, this.getWidth() - 30, 3, 20);

		if (MainMidlet.islogin)
			g.drawString("员工:" + MainMidlet.glbUserName, 10, this.getHeight()
					- bottom + 2, 20);
		else
			g.drawString("员工:未登录", 10, this.getHeight() - bottom + 2, 20);
		g.drawString("PDA:" + MainMidlet.PDAID, 120, this.getHeight() - bottom
				+ 2, 20);
		g.drawString("收银点:" + MainMidlet.posName, 10, this.getHeight() - bottom
				+ 17, 20);
		g.drawString("位置:" + MainMidlet.areaName, 120, this.getHeight()
				- bottom + 17, 20);
		
		for (int i = 0; i < cols; i++)
			for (int j = 0; j < rows; j++) {
				drawATable(g, i, j);
			}
	}

	protected void keyPressed(int keycode) {
		int x=curX;
		int y=curY;
		switch (getGameAction(keycode)) {
		case Canvas.DOWN:
			if ((y < rows - 1)&&(cur_tables[x][++y]!=null)){
				curY++;
				repaint();
			}
			break;
		case Canvas.UP:
			if ((y > 0)&&(cur_tables[x][--y]!=null)) {
				curY--;
				repaint();
			}
			break;
		case Canvas.LEFT:
			if ((x > 0)&&(cur_tables[--x][y]!=null)) {
				curX--;
				repaint();
			}
			break;
		case Canvas.RIGHT:
			if ((x < cols - 1)&&(cur_tables[++x][y]!=null)) {
				curX++;
				repaint();
			}
			break;
		}
		
		switch (keycode){
		case Canvas.KEY_NUM1://前翻页
			if (curPage>0){
				curPage--;
				curX=0;
				curY=0;
				initShowTable();
				repaint();
			}
			break;
		case Canvas.KEY_NUM3://后翻页
			if (curPage<pages-1){
				curPage++;
				curX=0;
				curY=0;
				initShowTable();
				repaint();
			}
			break;
		}
	}
	
	public void commandAction(Command c, Displayable s) {
		String cmd = c.getLabel();
		if (cmd.equals("开台")){
			if (cur_tables[curX][curY].getStatus()!=Table.ST_free){
				showInfo(cur_tables[curX][curY].getTableNo()
						+"号桌的状态不是空闲,不可以开台!");
				return;
			}
		}
		else if (cmd.equals("点菜")||cmd.equals("退菜")||cmd.equals("催菜")){
			if (cur_tables[curX][curY].getStatus()!=Table.ST_use){
				showInfo(cur_tables[curX][curY].getTableNo()
						+"号桌没有客人消费,不可以"+cmd+"!");
				return;
			}
		}
		Navigator.flow(cmd);
	}
	
	/**
	 * 初始化桌台
	 * @param tables 桌台数组
	 */
	public void createTables(Table[] tables){
		all_tables=null;
		all_tables=tables;
		curPage=0;
		curX=0;
		curY=0;
		
		tableCount=tables.length;
		pages=tableCount/(rows*cols);
		if (tableCount%(rows*cols)!=0)
			pages++;
		
		initShowTable();
		repaintTable();
		repaintTop();
	}

	/**
	 * 重绘界面底部显示信息
	 *
	 */
	public void repaintBottom()
	{
		repaint(0,this.getHeight() - bottom, this.getWidth(),bottom);
	}
	
	/**
	 * 重绘界面顶部显示信息
	 *
	 */
	public void repaintTop()
	{
		repaint(0,0,this.getWidth(),top);
	}
	
	/**
	 * 重绘桌台显示区域
	 *
	 */
	public void repaintTable()
	{
		repaint(0,top,this.getWidth(),this.getHeight()-top-bottom);
	}
	
	/**
	 * 根据登录情况初始化菜单
	 *
	 */
	public void initMenu()
	{
		if (MainMidlet.islogin){
			addCommand(cmd_Table);
			addCommand(cmd_Dish);
			removeCommand(cmd_Login);
		}
		else{
			removeCommand(cmd_Table);
			removeCommand(cmd_Dish);
			addCommand(cmd_Login);
		}
	}
	
	/**
	 * 显示提示信息
	 * @param str
	 */
	public void showInfo(String str)
	{
		ticker.setString(str);
	}
	
	/**
	 * 获取选中的桌号
	 * @return 选中的桌号
	 */
	public String getCurTableNo()
	{
		return cur_tables[curX][curY].getTableNo();
	}
	
	/**
	 * 获取选中的桌台
	 * @return 选中的桌台
	 */
	public Table getCurTable()
	{
		return cur_tables[curX][curY];
	}
	
	/**
	 * 获取选中桌台的状态
	 * @return 选中桌台的状态
	 */
	public int getCurTableStatus(){
		if (cur_tables[curX][curY]!=null)
			return cur_tables[curX][curY].getStatus();
		else
			return 0;
		
	}
}

⌨️ 快捷键说明

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