Ilias
Posts: 1
Nickname: eli
Registered: May, 2003
Java MIDlets
Posted: May 7, 2003 7:59 AM
Advertisement
I am got a source code for the MIDlet... Could any please modify, such that when I press "left+up" , it should display an arrow about an anlge of 45 degrees , similarly for all the combinations (that is left+down, up+right, up+left, down+right)..Thanks a lot....Waiting for your answer... import javax.microedition.lcdui.*; import com.nokia.mid.ui.*; import javax.microedition.lcdui.Canvas; public class Displayable1 extends Canvas implements CommandListener { Font font1 = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_SMALL); boolean rechterSoftkey,linkerSoftkey,send,up,down,left,right,stern,raute,eins,zwei,drei ,vier,f?nf,sechs,sieben,acht,neun,zehn,gamea,gameb,gamec,gamed,fire = false; boolean rechterSoftkeyRe,linkerSoftkeyRe,sendRe,upRe,downRe,leftRe,rightRe,sternRe,raut eRe,einsRe,zweiRe,dreiRe,vierRe,f?nfRe,sechsRe,siebenRe,achtRe,neunRe,zehnRe,gam eaRe,gamebRe,gamecRe,gamedRe,fireRe = false; int keyValue,gameValue=0; Canvas can; MIDlet1 midlet; public Displayable1(MIDlet1 midlet) { this.midlet = midlet; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception {} public void commandAction(Command command, Displayable displayable){} protected void paint(Graphics g) { int x; x= getWidth()/2-28; g.setColor(255,255,255); g.fillRect(0,0,getWidth(),getHeight()); g.setColor(0,255,0); if(zehn)g.fillRect(x+21,109,14,14); if(eins)g.fillRect(x,45,14,14); if(zwei)g.fillRect(x+21,45,14,14); if(drei)g.fillRect(x+42,45,14,14); if(vier)g.fillRect(x,66,14,14); if(f?nf)g.fillRect(x+21,66,14,14); if(sechs)g.fillRect(x+42,66,14,14); if(sieben)g.fillRect(x,87,14,14); if(acht)g.fillRect(x+21,87,14,14); if(neun)g.fillRect(x+42,87,14,14); if(up)g.fillRect(x+23,21,10,10); if(down)g.fillRect(x+23,31,10,10); if(left)g.fillRect(x+13,26,10,10); if(right)g.fillRect(x+33,26,10,10); if(stern)g.fillRect(x,109,14,14); if(raute)g.fillRect(x+42,109,14,14); if(linkerSoftkey)g.fillRect(x+7,9,14,7); if(rechterSoftkey)g.fillRect(x+35,9,14,7); if(send)g.fillRect(x,23,7,14); g.setColor(0,0,255); if(zehnRe)g.fillRect(x+21,109,14,14); if(einsRe)g.fillRect(x,45,14,14); if(zweiRe)g.fillRect(x+21,45,14,14); if(dreiRe)g.fillRect(x+42,45,14,14); if(vierRe)g.fillRect(x,66,14,14); if(f?nfRe)g.fillRect(x+21,66,14,14); if(sechsRe)g.fillRect(x+42,66,14,14); if(siebenRe)g.fillRect(x,87,14,14); if(achtRe)g.fillRect(x+21,87,14,14); if(neunRe)g.fillRect(x+42,87,14,14); if(upRe)g.fillRect(x+23,21,10,10); if(downRe)g.fillRect(x+23,31,10,10); if(leftRe)g.fillRect(x+13,26,10,10); if(rightRe)g.fillRect(x+33,26,10,10); if(sternRe)g.fillRect(x,109,14,14); if(rauteRe)g.fillRect(x+42,109,14,14); if(linkerSoftkeyRe)g.fillRect(x+7,9,14,7); if(rechterSoftkeyRe)g.fillRect(x+35,9,14,7); if(sendRe)g.fillRect(x,23,7,14); g.setFont(font1); g.setColor(0,0,0);//black g.drawRect(x,23,7,14);//send g.drawRect(x,45,14,14);g.drawString("1",x+4,45+3,0);//eins g.drawRect(x,66,14,14);g.drawString("4",x+4,66+3,0);//vier g.drawRect(x,87,14,14);g.drawString("7",x+4,87+3,0);//sieben g.drawRect(x,109,14,14);g.drawString("*",x+4,109+3,0);//stern g.drawRect(x+21,45,14,14);g.drawString("2",x+25,45+3,0);//zwei g.drawRect(x+21,66,14,14);g.drawString("5",x+25,66+3,0);//f?nf g.drawRect(x+21,87,14,14);g.drawString("8",x+25,87+3,0);//acht g.drawRect(x+21,109,14,14);g.drawString("0",x+25,109+3,0);//zehn g.drawRect(x+42,45,14,14);g.drawString("3",x+46,45+3,0);//drei g.drawRect(x+42,66,14,14);g.drawString("6",x+46,66+3,0);//sechs g.drawRect(x+42,87,14,14);g.drawString("9",x+46,87+3,0);//neun g.drawRect(x+42,109,14,14);g.drawString("#",x+46,109+3,0);//raute g.drawRect(x+7,9,14,7);g.fillRect(x+10,12,9,2);//linkerSoftkey g.drawRect(x+35,9,14,7);g.fillRect(x+38,12,9,2);//rechterSoftkey g.drawRect(x+23,21,10,10);//up g.drawLine(x+28,24,x+28,28);g.drawLine(x+26,26,x+28,24);g.drawLine(x+28,24,x+30 ,26); g.drawLine(x+26,25,x+28,23);g.drawLine(x+28,23,x+30,25); g.drawRect(x+23,31,10,10);//down g.drawLine(x+28,34,x+28,38);g.drawLine(x+26,36,x+28,38);g.drawLine(x+28,38,x+30 ,36); g.drawLine(x+26,37,x+28,39);g.drawLine(x+28,39,x+30,37); g.drawRect(x+13,26,10,10);//left g.drawLine(x+16,31,x+20,31);g.drawLine(x+16,31,x+18,29);g.drawLine(x+16,31,x+18 ,33); g.drawLine(x+15,31,x+17,29);g.drawLine(x+15,31,x+17,33); g.drawRect(x+33,26,10,10);//right g.drawLine(x+36,31,x+40,31);g.drawLine(x+38,29,x+40,31);g.drawLine(x+38,33,x+40 ,31); g.drawLine(x+39,29,x+41,31);g.drawLine(x+39,33,x+41,31); g.drawRect(x+49,23,7,14);//end if(keyValue!=0){ g.drawString("keyCode: ",0,0,0); g.drawString(" "+String.valueOf(keyValue),0,font1.getHeight()+5,0); } try {gameValue = getGameAction(keyValue); g.drawString("game action: ",getWidth()-font1.stringWidth("game action: "),0,0); switch(gameValue){ case 0:g.drawString("NONE",getWidth()-font1.stringWidth("NONE "),font1.getHeight()+5,0);break; case 1:g.drawString("UP",getWidth()-font1.stringWidth("UP "),font1.getHeight()+5,0);break; case 2:g.drawString("LEFT",getWidth()-font1.stringWidth("LEFT "),font1.getHeight()+5,0);break; case 5:g.drawString("RIGHT",getWidth()-font1.stringWidth("RIGHT "),font1.getHeight()+5,0);break; case 6:g.drawString("DOWN",getWidth()-font1.stringWidth("DOWN "),font1.getHeight()+5,0);break; case 8:g.drawString("FIRE",getWidth()-font1.stringWidth("FIRE "),font1.getHeight()+5,0);break; case 9:g.drawString("A",getWidth()-font1.stringWidth("A "),font1.getHeight()+5,0);break; case 10:g.drawString("B",getWidth()-font1.stringWidth("B "),font1.getHeight()+5,0);break; case 11:g.drawString("C",getWidth()-font1.stringWidth("C "),font1.getHeight()+5,0);break; case 12:g.drawString("D",getWidth()-font1.stringWidth("D "),font1.getHeight()+5,0);break; } }catch(IllegalArgumentException e){ } } public void keyPressed(int i){ if(i==KEY_NUM0)zehn=true; if(i==KEY_NUM1)eins=true; if(i==KEY_NUM2)zwei=true; if(i==KEY_NUM3)drei=true; if(i==KEY_NUM4)vier=true; if(i==KEY_NUM5)f?nf=true; if(i==KEY_NUM6)sechs=true; if(i==KEY_NUM7)sieben=true; if(i==KEY_NUM8)acht=true; if(i==KEY_NUM9)neun=true; if(i==-1)up=true; if(i==-2)down=true; if(i==-3)left=true; if(i==-4)right=true; if(i==KEY_STAR)stern=true; if(i==KEY_POUND)raute=true; if(i==-6)linkerSoftkey=true; if(i==-7)rechterSoftkey=true; if(i==-10)send=true; if(i==FIRE)fire=true; if(i==GAME_A)gamea=true; if(i==GAME_B)gameb=true; if(i==GAME_C)gamec=true; if(i==GAME_D)gamed=true; keyValue = i; repaint(); } public void keyRepeated(int i){ if(i==KEY_NUM0)zehnRe=true; if(i==KEY_NUM1)einsRe=true; if(i==KEY_NUM2)zweiRe=true; if(i==KEY_NUM3)dreiRe=true; if(i==KEY_NUM4)vierRe=true; if(i==KEY_NUM5)f?nfRe=true; if(i==KEY_NUM6)sechsRe=true; if(i==KEY_NUM7)siebenRe=true; if(i==KEY_NUM8)achtRe=true; if(i==KEY_NUM9)neunRe=true; if(i==-1)upRe=true; if(i==-2)downRe=true; if(i==-3)leftRe=true; if(i==-4)rightRe=true; if(i==KEY_STAR)sternRe=true; if(i==KEY_POUND)rauteRe=true; if(i==-6)linkerSoftkeyRe=true; if(i==-7)rechterSoftkeyRe=true; if(i==-10)sendRe=true; if(i==FIRE)fireRe=true; if(i==GAME_A)gameaRe=true; if(i==GAME_B)gamebRe=true; if(i==GAME_C)gamecRe=true; if(i==GAME_D)gamedRe=true; repaint(); } public void keyReleased(int i){ if(i==KEY_NUM0)zehn=zehnRe=false; if(i==KEY_NUM1)eins=einsRe=false; if(i==KEY_NUM2)zwei=zweiRe=false; if(i==KEY_NUM3)drei=dreiRe=false; if(i==KEY_NUM4)vier=vierRe=false; if(i==KEY_NUM5)f?nf=f?nfRe=false; if(i==KEY_NUM6)sechs=sechsRe=false; if(i==KEY_NUM7)sieben=siebenRe= false; if(i==KEY_NUM8)acht=achtRe=false; if(i==KEY_NUM9)neun=neunRe=false; if(i==-1)up=upRe=false; if(i==-2)down=downRe=false; if(i==-3)left=leftRe=false; if(i==-4)right=rightRe=false; if(i==KEY_STAR)stern=sternRe=false; if(i==KEY_POUND)raute=rauteRe=false; if(i==-6)linkerSoftkey=linkerSoftkeyRe=false; if(i==-7)rechterSoftkey=rechterSoftkeyRe=false; if(i==-10)send=sendRe=false; if(i==FIRE)fire=fireRe=false; if(i==GAME_A)gamea=gameaRe=false; if(i==GAME_B)gameb=gamebRe=false; if(i==GAME_C)gamec=gamecRe=false; if(i==GAME_D)gamed=gamedRe=false; keyValue=0; repaint(); } }