Color.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- package ColorDemo;
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- /**
- * A Color chooser MIDlet.
- */
- public class Color extends MIDlet implements CommandListener {
- /** This MIDlets Display object */
- private Display display; // Our display
- /** The Color chooser */
- private ColorChooser chooser;
- /** The Exit Command */
- private Command exitCommand = new Command("Exit", Command.EXIT, 1);
- /** The Decimal Command */
- private Command decimalCommand = new Command("Decimal", Command.SCREEN, 7);
- /** The Hexadecimal Command */
- private Command hexCommand = new Command("Hexadecimal", Command.SCREEN, 7);
- /** The Coarse command */
- private Command coarseCommand = new Command("Coarse", Command.SCREEN, 8);
- /** The Fine command */
- private Command fineCommand = new Command("Fine", Command.SCREEN, 8);
- /**
- * Construct a new Color MIDlet and initialize.
- */
- public Color() {
- display = Display.getDisplay(this);
- chooser = new ColorChooser(display.isColor(), display.numColors());
- chooser.addCommand(exitCommand);
- chooser.addCommand(hexCommand);
- chooser.addCommand(fineCommand);
- chooser.setCommandListener(this);
- chooser.setColor(0xffff00);
- }
- /**
- * Create the ColorChooser and make it current
- */
- public void startApp() {
- display.setCurrent(chooser);
- }
- /**
- * Pause
- */
- public void pauseApp() {
- }
- /**
- * Destroy must cleanup everything.
- * @param unconditional true if must destroy
- */
- public void destroyApp(boolean unconditional) {
- }
- /**
- * Respond to a commands issued on any Screen.
- * @param c Command invoked
- * @param s Displayable on which the command was invoked
- */
- public void commandAction(Command c, Displayable s) {
- if (c == exitCommand) {
- destroyApp(true);
- notifyDestroyed();
- } else if (c == decimalCommand) {
- chooser.setRadix(10);
- chooser.removeCommand(decimalCommand);
- chooser.addCommand(hexCommand);
- } else if (c == hexCommand) {
- chooser.setRadix(16);
- chooser.removeCommand(hexCommand);
- chooser.addCommand(decimalCommand);
- } else if (c == fineCommand) {
- chooser.setDelta(4);
- chooser.removeCommand(fineCommand);
- chooser.addCommand(coarseCommand);
- } else if (c == coarseCommand) {
- chooser.setDelta(32);
- chooser.removeCommand(coarseCommand);
- chooser.addCommand(fineCommand);
- }
- }
- }