I can't figure it out. Everything compiles fine, the output should draw a graph of the function, but when you start it is a blank screen.
import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; public class GraphTest extends MIDlet { private Display display; public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void startApp() { Graph graph = new Graph(); display.getDisplay(this); display.setCurrent(graph); } } class Graph extends Canvas { public void paint(Graphics g) { int width = g.getClipWidth(); int height = g.getClipHeight(); g.setColor(255, 0, 0); g.fillRect(0, 0, width, height); g.setColor(0, 0, 0); g.drawRect(0, 0, width - 1, height - 1); g.drawLine(width / 2, 0, width / 2, height); g.drawLine(0, height / 2, width, height / 2); g.translate(width / 2, height / 2); g.setColor(255, 0, 0); for (int x = -width / 2; x < width / 2; x++) { int y = -x * x / 40; g.drawLine(x, y, x, y); } } }
According to the schedule from the book "E. Butkevich Writing programs and games for cell phones."