Mega Code Archive

 
Categories / Java Tutorial / J2ME
 

Get color from Display

import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.TextBox; import javax.microedition.midlet.MIDlet; public class J2MEcolorDetect extends MIDlet implements CommandListener {   private Command exitCommand = new Command("exit", Command.EXIT, 1);   private Display display;   public J2MEcolorDetect() {     display = Display.getDisplay(this);   }   public void startApp() {     TextBox t;     if (display.isColor())       t = new TextBox("A", "B" + display.numColors(), 256, 0);     else       t = new TextBox("C", "D" + display.numColors(), 256, 0);     t.addCommand(exitCommand);     t.setCommandListener(this);     display.setCurrent(t);   }   public void pauseApp() {   }   public void destroyApp(boolean unconditional) {   }   public void commandAction(Command c, Displayable s) {     if (c == exitCommand) {       destroyApp(false);       notifyDestroyed();     }   } }