手把手教你写第二个手机游戏
图片:
看了陈老师写的手把手教你写第一个手机游戏后,回去在家机器上试了试,嘿真有意思
看了相关的帮助文档后,觉得在J2ME上有许多方法都简化了,就比如Color类吧,居然颜
色要输入数值等.不过我觉得如果大家J2SE学的不错的话,很容易上手的.
我在陈老师的基础上,增加了绘图的功能:)
代码如下
------------------------------------------------------------------------------------
import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class exceone extends MIDlet implements CommandListener { private eCanvas canvas; public void startApp() { if(canvas==null) { canvas=new eCanvas(Display.getDisplay(this)); Command exitCommand=new Command("Exit",Command.EXIT,0); canvas.addCommand(exitCommand); canvas.setCommandListener(this); } canvas.start(); } public void pauseApp() { } public void destroyApp(boolean t) { } public void commandAction(Command c,Displayable s) { if(c.getCommandType()==Command.EXIT) { destroyApp(true); notifyDestroyed(); } } }
import javax.microedition.lcdui.*; public class eCanvas extends Canvas { private Display display; public eCanvas(Display d) { display=d; } void start() { display.setCurrent(this); repaint(); } public void paint(Graphics g) { g.setColor(255,255,255); //初始化背景设置为白色 g.fillRect(0,0,getWidth(),getHeight()); g.setColor(255,0,0); //设置颜色 g.drawArc(5,5,25,25,0,360); //画圆 g.setColor(0,255,0); g.drawArc(35,5,25,25,0,360); g.setColor(0,0,255); g.drawArc(65,5,25,25,0,360); g.setColor(255,255,0); g.drawArc(20,35,25,25,0,360); g.setColor(255,0,255); g.drawArc(50,35,25,25,0,360); g.setColor(10,50,100); g.drawString("上海黑暗之龙",100,100,Graphics.RIGHT | Graphics.TOP); } }
|