U E D R , A S I H C RSS

Mobile Java Study/Nine Nine

소개

메뉴로 단을 선택하여 구구단 출력.

재동이의 소스

~cpp 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*; 
 
public class NineNine extends MIDlet implements CommandListener{
    private Display display;
    private List list;
    private Form form;
    
    private Command backCommand = new Command("Back",Command.BACK,1);
    private Command nextCommand = new Command("Next",Command.SCREEN,1);
    private Command exitCommand = new Command("Exit",Command.EXIT,1);
    
    private String[] dan;
    private String str;
    
    public NineNine() {
    	dan = new String[8];
    	for(int i=2;i<10;i++)
    		dan[i-2] = String.valueOf(i) + " dan";
    		
    	list = new List("NineNine",List.IMPLICIT,dan,null);
    	
    	list.addCommand(nextCommand);
    	list.addCommand(exitCommand);
    	list.setCommandListener(this);
    	display = Display.getDisplay(this);
    }
    
    public void startApp() throws MIDletStateChangeException {
	   	display.setCurrent(list);
    } 
    
    public void pauseApp() { 
    } 
     
    public void destroyApp(boolean unconditional) { 
    	list = null;
    	nextCommand = null;
    	exitCommand = null;
    	display = null;
    } 
    public void calculNineNine() {
    	int dan = list.getSelectedIndex() + 2;
		form = new Form(String.valueOf(dan)+" dan");
		str = "";
		
		for(int i=1;i<10;i++)
			str += String.valueOf(dan)+" * "+i+" = "+String.valueOf(dan*i)+"\n";
		
    }
    public void commandAction(Command c,Displayable s) {
    	if (c == nextCommand) {
    		calculNineNine();
    		form.append(str);
    		
    		form.addCommand(backCommand);
    		form.addCommand(exitCommand);
    		form.setCommandListener(this);
    		display.setCurrent(form);
    	}
    	else if (c == exitCommand) {
    		destroyApp(true);
    		notifyDestroyed();
    	}
    	else if (c == backCommand) {
    		display.setCurrent(list);
    	}
    } 
} 

상규의 소스

~cpp 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class NineNine extends MIDlet implements CommandListener {
	Display display;

	List nineDanList;
	Form danForm;

	Command selectCommand;
	Command backCommand;
	Command exitCommand;

	public NineNine() {
		display = Display.getDisplay(this);

		nineDanList = new List("NineNine", List.IMPLICIT);

		selectCommand = new Command("Select", Command.SCREEN, 1);
		backCommand = new Command("Back", Command.BACK, 1);
		exitCommand = new Command("Exit", Command.EXIT, 1);

		for(int i = 2 ; i <= 9 ; i++) {
			nineDanList.append(String.valueOf(i) + " dan", null);
		}

		nineDanList.addCommand(selectCommand);
		nineDanList.addCommand(exitCommand);
		nineDanList.setCommandListener(this);
	}

	public void startApp() {
		display.setCurrent(nineDanList);
	}

	public void pauseApp() {
	}

	public void destroyApp(boolean unconditional) {
		display = null;
		nineDanList = null;
		danForm = null;
		selectCommand = null;
		backCommand = null;
		exitCommand = null;
	}

	public void commandAction(Command c, Displayable d) {
		if(c == selectCommand) {
			int dan = nineDanList.getSelectedIndex() + 2;
			danForm = new Form(String.valueOf(dan) + " dan");

			for(int i = 1 ; i <= 9 ; i++) {
				danForm.append(String.valueOf(dan) + " * " + String.valueOf(i)
						 + " = " + String.valueOf(dan * i) + "\n");
			}

			danForm.addCommand(backCommand);
			danForm.addCommand(exitCommand);
			danForm.setCommandListener(this);

			display.setCurrent(danForm);
		}
		else if(c == backCommand) {
			danForm = null;
			display.setCurrent(nineDanList);
		}
		else if(c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();
		}
	}
};
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:46
Processing time 0.0124 sec