FileDocCategorySizeDatePackage
Chooser.javaAPI DocJ2ME MIDP 2.03478Thu Nov 07 12:02:16 GMT 2002example.chooser

Chooser

public class Chooser extends MIDlet implements CommandListener

Fields Summary
private Display
display
private FontChooser
fonts
private TextSample
sample
private ColorChooser
colors
private Command
exitCommand
private Command
textColorCommand
private Command
backgroundColorCommand
private Command
fontsCommand
private Command
aboutCommand
private Command
okCommand
private Command
okFgCommand
private Command
okBgCommand
Constructors Summary
public Chooser()


      
	display = Display.getDisplay(this);
	sample = new TextSample();
	
	sample.addCommand(exitCommand);
	sample.addCommand(aboutCommand);
	sample.addCommand(textColorCommand);
	sample.addCommand(backgroundColorCommand);
	sample.addCommand(fontsCommand);
	sample.setCommandListener(this);
    
Methods Summary
public voidcommandAction(Command c, Displayable s)

	if (c == exitCommand) {
	    destroyApp(true);
	    notifyDestroyed();
	} else if (c == aboutCommand) {
	    About.showAbout(display);
	} else if (c == fontsCommand) {
	    if (fonts == null) {
		fonts = new FontChooser();
		fonts.setFace(sample.getFace());
		fonts.setStyle(sample.getStyle());
		fonts.setSize(sample.getSize());
		fonts.addCommand(okCommand);
		fonts.setCommandListener(this);
	    }
	    display.setCurrent(fonts);
	} else if (c == backgroundColorCommand) {
	    if (colors == null) {
		colors = new ColorChooser(display.isColor(), 
					  display.numColors());
		colors.setCommandListener(this);
	    }
	    colors.addCommand(okBgCommand);
	    colors.removeCommand(okFgCommand);
	    colors.setColor(sample.getBackgroundColor());
	    display.setCurrent(colors);
	} else if (c == textColorCommand) {
	    if (colors == null) {
		colors = new ColorChooser(display.isColor(), 
					  display.numColors());
		colors.setCommandListener(this);
	    }
	    colors.addCommand(okFgCommand);
	    colors.removeCommand(okBgCommand);

	    colors.setColor(sample.getForegroundColor());
	    display.setCurrent(colors);
	} else if (c == okCommand) {
	    if (s == fonts) {
		sample.setStyle(fonts.getStyle());
		sample.setFace(fonts.getFace());
		sample.setSize(fonts.getSize());
	    }
	    display.setCurrent(sample);
	} else if (c == okFgCommand) {
	    sample.setForegroundColor(colors.getColor());
	    display.setCurrent(sample);
	} else if (c == okBgCommand) {
	    sample.setBackgroundColor(colors.getColor());
	    display.setCurrent(sample);
	}
    
public voiddestroyApp(boolean unconditional)
Destroy must cleanup everything.

    
public voidpauseApp()
Pause

    
public voidstartApp()
Create the FontChooser and make it current

	display.setCurrent(sample);