J2ME图片浏览器

package Mypaint;


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDletStateChangeException;


public class mypaint extends MIDlet {
private Display d;
private mycanvas mc;
public mypaint() {
d = Display.getDisplay(this);
mc = new mycanvas(this);
// TODO Auto-generated constructor stub
}


protected void destroyApp(boolean arg0) //throws MIDletStateChangeException
{}


protected void pauseApp() {}


protected void startApp() throws MIDletStateChangeException {
d.setCurrent(mc);
}
public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}


}


class mycanvas extends Canvas implements CommandListener
{
private Image ima[] = new Image[11];
private Command last;
private Command next;
mypaint mp;;
private int x,y,n=0;;
public mycanvas(mypaint mp)
{
try{
for(int i=1;i<=10;i++)
{
ima[i-1] = Image.createImage("/"+i+".png");
}
}catch(Exception e){}
x = getWidth();
y = getHeight();
this.mp = mp;
last = new Command("上一个",Command.EXIT,1);
next = new Command("下一个",Command.SCREEN,2);
addCommand(last);
addCommand(next);
setCommandListener(this);
}
public void paint(Graphics g)
{
g.setColor(255,255,255);
g.drawRect(0,0,x,y);
g.drawImage(ima[n],x/2,y/2,g.HCENTER | g.VCENTER);
}
public void commandAction(Command c,Displayable d)
{
if(c == last)
{
if(n>=1)
n--;
else if(n==0)
n=9;
repaint();
}else if(c == next)
{
if(n<9)
n++;
else if(n==9)
n=0;
repaint();
}
}
public void keyPressed(int k)
{
switch(getGameAction(k))
{
case Canvas.UP:if(n>0)n--;
break;

case Canvas.DOWN:if(n<9)n++;
break;

case Canvas.LEFT:if(n>0)n--;
break;

case Canvas.RIGHT:if(n<9)n++;
break;
}
repaint();

}

} J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器 J2ME图片浏览器



你可能感兴趣的:(j2me)