To develop menu based application to draw shapes > Java ME Program
To develop menu based application to draw shapes > Java ME Program
Mobile Communication and Computing
Program:
package mobileapplication1;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Midlet extends MIDlet
{
Display d;
DrawCan dv;
public void startApp(){
dv= new DrawCan();
d=Display.getDisplay(this);
d.setCurrent(dv);
}
class DrawCan extends Canvas implements CommandListener{
Command rect,tri,circle;
int flag;
DrawCan(){
rect=new Command("Rect",null,Command.SCREEN,0);
tri=new Command("Triangle",null,Command.SCREEN,1);
circle=new Command("Circle",null,Command.SCREEN,2);
addCommand(rect);
addCommand(tri);
addCommand(circle);
setCommandListener(this);
}
protected void paint(Graphics g){
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
if(flag==1){
g.setColor(0, 0, 255);
g.drawRect(50, 50, 150, 150);
g.setColor(255, 0, 0);
g.fillRect(52, 52, 148, 148);
}
else if(flag==2)
{
g.setColor(0, 0, 255);
g.drawLine(50, 50, 200, 75);
g.drawLine(200, 75, 50, 200);
g.drawLine(50, 200, 50, 50);
g.setColor(255, 0, 0);
g.fillTriangle(51, 51,199,74,51,199);
}
else if(flag==3)
{
g.setColor(0, 0, 255);
g.drawArc(50, 50, 150, 150,180,360);
g.setColor(255, 0, 0);
g.fillArc(52, 52, 148, 148,180,360);
}
}
public void commandAction(Command c, Displayable d)
{
if(c==rect)
{
flag=1;
}
else if(c==tri)
{
flag=2;
}
else if(c==circle)
{
flag=3;
}
repaint();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Output:
Comments
Post a Comment