j2me Wizard animation to achieve the classic case studies – iteye technology website

August 1, 2011
=================== j2me Wizard animation to achieve the classic case study ==========
Today Beijing Qinghe Miles, particularly cheerful mood, now in training students more obedient here, is also more to love learning, in general people feel particularly pro, now written the day before j2me animation to achieve the spirit to share with you, we want to help.
j2me animation game overall feeling is relatively easy to understand, as long as you can reflect changes to the point of view is how the animation wizard then you realize it should be understood not a problem.
Oh. . I said so much to see how to achieve the wizard animation
/ / This article is reproduced Please do not write your own, or to pay the liability package com.redarmy.canvas01; import javax.microedition.lcdui.Canvas ; import javax.microedition.lcdui.Graphics; public class ExCanvas extends Canvas {public int px = 60, py = 80; / / the starting coordinates public int arc1 = 30, arc2 = 280; / / starting point / / elf direction is defined public static final int UP = 1; public static final int DOWN = 2; public static final int LEFT = 3; public static final int RIGHT = 4; / / initialize the direction of the public int DIR = 4; protected void paint ( Graphics arg0) {arg0.setColor (0, 255, 0); arg0.fillRect (0, 0, this.getWidth (), this.getHeight ()); arg0.setColor (255, 0, 0); switch (DIR ) {case UP: arg0.fillArc (px, py, 50, 50, arc1 90, arc2); / / turn up the degree of 90 ° break; case DOWN: arg0.fillArc (px, py, 50, 50, arc1 270, arc2); / / Turn down the degree of 270 ° break; case LEFT: arg0.fillArc (px, py, 50, 50, arc1 180, arc2); / / to the right degree of 180 ° break; case RIGHT: arg0.fillArc (px, py, 50, 50, arc1, arc2); / / initialize the direction of 0 ° break; default: break;}} / / key handler protected void keyPressed (int keyCode) {System.out.println (keyCode); arc1 = 30; arc2 = 280; / / When the button when the angle changes / / right if (keyCode ==- 4| keyCode == 54) {DIR = RIGHT; px = 8; if (px> = this.getWidth ()) {px = 0;}} / / next if (keyCode ==- 2| keyCode == 56) {DIR = DOWN; py = 8; if (py> = this.getHeight () ) {py = 0;}} / / the if (keyCode ==- 1| keyCode == 50) {DIR = UP; py-= 8; if (py <= 0) {py = this.getHeight () ;}} / / left if (keyCode ==- 3| keyCode == 52) {DIR = LEFT; px-= 8; if (px <= 0) {px = this.getWidth ();}} this. repaint ();} protected void keyReleased (int keyCode) {arc1 = 50; arc2 = 240; / / When you release the key is the angle changes this.repaint ();} protected void keyRepeated (int keyCode) {}} / / < br />
/ / test class package com.redarmy.canvas01; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeExcepti on; public class AppMain extends MIDlet {public ExCanvas ecs; public AppMain () {ecs = new ExCanvas ();} protected void destroyApp (boolean arg0) throws MIDletStateChangeException {} protected void pauseApp () {} protected void startApp () throws MIDletStateChangeException {Display.getDisplay (this ). setCurrent (ecs);}}
above article are my own writing, please do not arbitrarily reproduced, or legal responsibility to pay. If in doubt, please send E-mail: RedArmy.Chen @ gmail.com I will get back to you