Public Class Primitivedraw Extends Midlet Implements Commandlistener (

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

import javax.microedition.midlet.

*;
import javax.microedition.lcdui.*;
import java.util.*;
public class PrimitiveDraw extends MIDlet
implements CommandListener {
private Command exitCommand;
private Display display;
private DrawCanvas screen;
public PrimitiveDraw() {
// Get the Display object for the MIDlet
display = Display.getDisplay(this);
// Create the Exit command
exitCommand = new Command("Exit",
Command.EXIT, 2);
// Create the main screen form
screen = new DrawCanvas();
// Set the Exit command
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws
MIDletStateChangeException {
// Set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {

}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c,
Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class DrawCanvas extends Canvas {
public void paint(Graphics g) {
// Draw the first row of circles
g.setColor(0, 0, 255); // Blue
g.drawArc(5, 5, 25, 25, 0, 360);
g.setColor(255,255, 255); // Black
g.drawArc(35, 5, 25, 25, 0, 360);
g.setColor(255, 0, 0); // Red
g.drawArc(65, 5, 25, 25, 0, 360);
// Draw the second row of circles
g.setColor(255, 255, 0); // Yellow
g.drawArc(20, 20, 25, 25, 0, 360);
g.setColor(0, 255, 0); // Green
g.drawArc(50, 20, 25, 25, 0, 360);
g.drawLine(5, 5, 60, 60);
g.setColor(0, 0, 255); // Blue
g.drawLine(35, 60, 90, 5);

//Draw rectangles
g.setColor(0, 0, 255); // Blue
g.drawRect(40, 80, 70, 40);
}
}

You might also like