Vous êtes sur la page 1sur 4

http://stackoverflow.

com/questions/7821261/which-eclipse-download-for-developing -for-jave-me

http://technet.microsoft.com/en-us/sysinternals/bb842059

import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; public class TrucXanh extends MIDlet implements CommandListener { private Display display; private private private private Form mainForm; Command exitCommand; Command newCommand; Command selectCommand;

private Image[] arImage = new Image[6]; private ImageItem[] arImageItem = new ImageItem[12]; private int[] arIndex = new int[12]; // luu index private int[] itemNum = new int[12]; private boolean newGame = true; // game moi bat dau, nhan lenh " New" thi newGame = false private Random number = new Random(); // private StringItem strItem = new StringItem("adasdasd", "1"); public TrucXanh() { display = Display.getDisplay(this); newCommand = new Command("New", Command.ITEM, 2); exitCommand = new Command("Exit", Command.EXIT, 3); selectCommand = new Command("Select", Command.OK, 1); mainForm = new Form("Truc Xanh"); mainForm.addCommand(newCommand); mainForm.addCommand(exitCommand); //setSelectCommand(selectCommand); // mainForm.append(strItem); mainForm.setCommandListener(this);

try { for (int i = 0; i < 6; i++) { String str = "/image" + Integer.toString(i+1) + ".png"; Image temp = Image.createImage(str); arImage[i] = createThumbnail(temp); //mainForm.append(new ImageItem(null, arImage[i] , ImageItem.LAYOUT_LEFT, null)); } } catch (java.io.IOException e) { System.err.println("Unable to locate or read .png file") ; } } public void startApp() { // for (int i=0;i<12;i++) // { // mainForm.append(new ImageItem(null, arImage[arIndex[i]], ImageItem.LAYOUT_CENTER, null)); // } display.setCurrent(mainForm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == newCommand) { taoMangIndex(); if (newGame == false) { mainForm.deleteAll(); } else newGame = false; for (int i=0;i<12;i++) { arImageItem[i] = new ImageItem(null, arImage[arI ndex[i]], ImageItem.LAYOUT_CENTER, null); arImageItem[i].setDefaultCommand(selectCommand); itemNum[i] = mainForm.append(arImageItem[i]); }

} else if (c == exitCommand) { destroyApp(false); notifyDestroyed(); return; } else if (c == selectCommand) { if (s instanceof ImageItem) { ImageItem img = (ImageItem)s; } } // // // // // } if (c.getCommandType() == Command.OK) { StringItem strItem = new StringItem("label", "text"); mainForm.append(strItem); }

private Image createThumbnail(Image image) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); int thumbWidth = 55; int thumbHeight = 75; // // if (thumbHeight == -1) thumbHeight = thumbWidth * sourceHeight / sourceWidth; Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; y++) { for (int x = 0; x < thumbWidth; x++) { g.setClip(x, y, 1, 1); int dx = x * sourceWidth / thumbWidth; int dy = y * sourceHeight / thumbHeight; g.drawImage(image, x - dx, y - dy, Graphics.LEFT ; } } Image immutableThumb = Image.createImage(thumb); return immutableThumb; } public void taoMangIndex() { int count = 0; for (int i=0; i<12; i++)

Graphics.TOP)

{ count = 0; int temp = random(6); for (int j=0;j<i;j++) { if (arIndex[j] == temp) count++; } if (count <= 1) arIndex[i] = temp; else i--; } // // // // // // // } public int random(int max){ int i = number.nextInt(); number.setSeed(System.currentTimeMillis() + 2*number.nextInt() ); if (i < 0) i = -i; return i % max; } } String str = ""; for (int i=0;i<12;i++) { str += Integer.toString(arIndex[i]); } strItem.setText(str);

Vous aimerez peut-être aussi