0% found this document useful (0 votes)
27 views

Public Class Primitivedraw Extends Midlet Implements Commandlistener (

This Java program draws basic shapes like circles, lines, and rectangles on a canvas. It creates a DrawCanvas class that extends the Canvas class and overrides the paint method. The paint method draws circles of different colors in rows, lines crossing diagonally, and a blue rectangle. The PrimitiveDraw class implements the MIDlet and CommandListener interfaces and initializes the display, canvas, and exit command for the drawing app.

Uploaded by

Mina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Public Class Primitivedraw Extends Midlet Implements Commandlistener (

This Java program draws basic shapes like circles, lines, and rectangles on a canvas. It creates a DrawCanvas class that extends the Canvas class and overrides the paint method. The paint method draws circles of different colors in rows, lines crossing diagonally, and a blue rectangle. The PrimitiveDraw class implements the MIDlet and CommandListener interfaces and initializes the display, canvas, and exit command for the drawing app.

Uploaded by

Mina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 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