//---classTest.java (메인클래스)
//여긴 별다른거 없고 메뉴를 불러오는 기능만 한다.
import org.kwis.msp.lcdui.*;
public class classTest extends Jlet
{
Display display;
protected void startApp(String[] args)
{
display = Display.getDefaultDisplay();
MainCard = new MainCard();
display.pushCard(MainCard);
}
protected void destroyApp(boolean b){}
}
//---cardReady.java (카드 및 display를 준비한다.)
//여기서 준비된 카드를 메인클래스를 제외한 모든 클래스에서 사용한다.
import org.kwis.msp.lcdui.*;
class cardReady {
Card MainCard = null;
Card subCard1 = null;
Card subCard2 = null;
Display display;
public cardReady()
{
display = Display.getDefaultDisplay();
}
}
//---MainCard.java (메뉴부분)
import org.kwis.msp.lcdui.*;
class MainCard extends Card {
cardReady cr = new cardReady();
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(0);
g.drawString("1.Menu1",0,10,Graphics.LEFT|Graphics.TOP);
g.drawString("2.Menu2",0,30,Graphics.LEFT|Graphics.TOP);
g.drawString("3.Menu3",0,50,Graphics.LEFT|Graphics.TOP);
g.drawString("4.Menu4",0,70,Graphics.LEFT|Graphics.TOP);
}
public boolean keyNotify(int type, int keyCode)
{
if(type == EventQueue.KEY_PRESSED)
{
switch(keyCode)
{
case 49: //1번키를 눌렀을경우 subCard1을 넣는다.
if(cr.subCard1 == null)
{
cr.subCard1 = new subCard1();
}
cr.display.popCard();
cr.display.pushCard(cr.subCard1);
break;
case 50: //2번키를 눌렀을 경우 subCard2를 넣는다.
if(cr.subCard2 == null)
{
cr.subCard2 = new subCard2();
}
cr.display.popCard();
cr.display.pushCard(cr.subCard2);
break;
case 51:
break;
case 52:
break;
}
}
return true;
}
}
//---subCard1.java (서브카드1)
import org.kwis.msp.lcdui.*;
class subCard1 extends Card {
cardReady cr = new cardReady();
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(0);
g.drawString("여기는 서브1페이지",0,10,Graphics.LEFT|Graphics.TOP);
g.drawString("* 메뉴로 이동",0,30,Graphics.LEFT|Graphics.TOP);
}
public boolean keyNotify(int type, int keyCode)
{
if(type == EventQueue.KEY_PRESSED && keyCode == 42)
{
if(cr.MainCard == null)
{
cr.MainCard = new MainCard();
}
cr.display.popCard();
cr.display.pushCard(cr.MainCard);
}
return true;
}
}
//---subCard2.java (서브카드2)
import org.kwis.msp.lcdui.*;
class subCard2 extends Card {
cardReady cr = new cardReady();
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(0);
g.drawString("여기는 서브2페이지",0,10,Graphics.LEFT|Graphics.TOP);
g.drawString("# 메뉴로 이동",0,30,Graphics.LEFT|Graphics.TOP);
}
public boolean keyNotify(int type, int keyCode)
{
if(type == EventQueue.KEY_PRESSED && keyCode == 35)
{
if(cr.MainCard == null)
{
cr.MainCard = new MainCard();
}
cr.display.popCard();
cr.display.pushCard(cr.MainCard);
}
return true;
}
}
--샘플파일
댓글 영역