To change color of a shape using Timer > Java ME Program

To change color of a shape using Timer > Java ME Program

Mobile Communication and Computing

Program: package prat; import java.util.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class Midlet extends MIDlet { Display d; MyCanvas m; Command rect; Timer t; MyTask mt; public void startApp() { d=Display.getDisplay(this); m=new MyCanvas(); d.setCurrent(m); t=new Timer(); mt=new MyTask(); t.schedule(mt,1000,1000); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } class MyCanvas extends Canvas{ protected void paint(Graphics g) { Random r=new Random(); g.setColor(0,0,0); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(r.nextInt(256),r.nextInt(256),r.nextInt(256)); g.fillRect(20,20,200,200); } } class MyTask extends TimerTask{ public void run() { m.repaint(); } } }

Output:


Comments

Popular posts from this blog

Intermediate Code Generation > C Program