import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import javax.microedition.midlet.*; import java.util.*; import java.lang.*; public class StudsApp extends MIDlet{ public Canvas canvasen = new canvas(); public static Vector vector = new Vector(); public void startApp(){ Display.getDisplay(this).setCurrent(canvasen); canvasen.setFullScreenMode(true); vector.addElement(new Boll()); } public void pauseApp(){ } public void destroyApp(boolean unconditional){ notifyDestroyed(); } } class canvas extends Canvas implements Runnable{ private Thread thread; public int width = getWidth(), height = getHeight(), x = 4, y = 4, vx = 1, vy = 1,randomx,randomy; Random r = new Random(); public canvas(){ new Thread(this).start(); } public void run(){ while(true){ for (int i = 0; i < StudsApp.vector.size(); i++) { ((Boll)StudsApp.vector.lastElement()).move(width,height); } } } public void paint(Graphics g){ g.setColor(0xFFFFFF); g.fillRect(0,0,width,height+100); for (int i = 0; i < StudsApp.vector.size(); i++) { ((Boll)StudsApp.vector.elementAt(i)).draw(g); repaint(); } } protected void keyPressed(int keyCode){ switch(keyCode){ case -3: vx -= 1; break; case -1: vy -= 1; break; case -4: vx += 1; break; case -2: vy += 1; break; case 53: StudsApp.vector.addElement(new Boll()); ((Boll)StudsApp.vector.lastElement()).vx = r.nextInt(2)+1; ((Boll)StudsApp.vector.lastElement()).vy = r.nextInt(2)+1; break; } } } class Boll{ static int x, y, color,radius, vx, vy; public Boll(){ x = 5; y = 5; vx = 1; vy = 1; radius = 10; color = 0x000000; } public static void move(int max_x,int max_y){ x += vx; y += vy; if(x > (max_x-radius) || x < 0) vx = -vx; if(y > (max_y) || y < 0) vy = -vy; } public void draw(Graphics g){ g.setColor(color); g.fillArc(x,y,radius,radius,0,360); } }