













































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Description about Java ME – Graphics and Multimedia, Displaying in MIDP, Canvas Class, What to Draw?,Where to Draw?, Still Where to Draw?.
Typology: Study notes
1 / 53
This page cannot be seen from the preview
Don't miss anything!














































1
Abstract method – only a method signature, no code Implemented method in our subclass
First coordinate Second coordinate Number of degrees in the arc – 360° would be a full circle
There is no drawTriangle, so how can we draw triangles?
Menu Draw Lines Draw Rectangle Draw RoundedRectangle Draw Triangle Draw Arc
Inherits from Canvas Need to implement the paint() method This property is set from the MIDlet to determine what shape to draw
else if(drawingType == 2) { // draw rectangle g.drawRect(w / 2, h / 2, 20, 20); g.fillRect((w / 2) - 20, (h / 2) - 20, 20, 20); } else if(drawingType == 3) { // draw rounded rectangle g.drawRoundRect((w / 2) - 50, (h / 2) - 60, 100, 120, 30, 50); } else if(drawingType == 4) { // draw filled triangle g.fillTriangle(0, 0, w / 2, h, w, 0); } else if(drawingType == 5) { // draw arc g.fillArc(w / 2, h / 2, 50, 50, 0, 180); } } Draw an outline and a filled rectangle Three coordinates 180° is half a circle
An instance of our Canvas subclass This method will set up the commands and display GraphicsCanvas Depending on the command selected, a different drawing type will be set and the Canvas repainted
public void commandAction(Command c, Displayable s) { if (c.getCommandType() == Command.EXIT) { notifyDestroyed(); } else if(c.getLabel() == "Draw Lines") { gc.setDrawType(1); gc.repaint(); } else if(c.getLabel() == "Draw Rectangle") { gc.setDrawType(2); gc.repaint(); } else if(c.getLabel() == "Draw Rounded Rectangle") { gc.setDrawType(3); gc.repaint(); } else if(c.getLabel() == "Draw Triangle") { gc.setDrawType(4); gc.repaint(); } else if(c.getLabel() == "Draw Arc") { gc.setDrawType(5); gc.repaint(); } } Check what command was selected Set drawing type in the GraphicsCanvas object Call repaint, which means the MIDP implementation will call the paint() method in the GraphicsCanvas object
Each colour component has to be between 0 and 255