selectlist.java

来自「有关手机游戏网络对战方面的源码」· Java 代码 · 共 54 行

JAVA
54
字号
package unicoco;

import java.io.IOException;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

public class SelectList extends List implements CommandListener {
	static SelectList instance;

	public SelectList(String[] labels, Image[] icons) {
		super("please select one", Choice.EXCLUSIVE, labels, icons);
		setFont(0, Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
				Font.SIZE_LARGE));
		setFont(1, Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
				Font.SIZE_LARGE));
		addCommand(new Command("Back", Command.BACK, 1));
		addCommand(new Command("OK", Command.OK, 1));
		setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if (c.getLabel().equalsIgnoreCase("back")) {
			MIDGame.display.setCurrent(MainMenu.getInstance());
		} else if(instance.getSelectedIndex()==0){
			MIDGame.display.setCurrent(Server.getInstance());
		}else{
			MIDGame.display.setCurrent(Client.getInstance());
		}
	}

	public final static Displayable getInstance() {
		if (SelectList.instance == null) {
			String[] labels = { "Server", "Client" };
			Image[] icons = new Image[2];
			try {
				icons[0] = Image.createImage("/serverIcon.png");
				icons[1] = Image.createImage("/clientIcon.png");
			} catch (IOException e) {
//				e.printStackTrace();
				MIDGame.game.notifyDestroyed();
			}
			SelectList.instance = new SelectList(labels, icons);
		}
		return SelectList.instance;
	}

}

⌨️ 快捷键说明

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