// ITU F2005 JMA - Mandatory assignment #1 // PlotCanvas.java // 2005-03-01 Kenn A. Thisted import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class PlotCanvas extends Canvas implements CommandListener { public static final int NAV_UP = -1; public static final int NAV_DOWN = -2; public static final int NAV_LEFT = -3; public static final int NAV_RIGHT = -4; public static final int NAV_SELECT = -5; private Mandatory1 midlet; private Plot plot; private Command exitCommand = new Command( "Exit", Command.EXIT, 1 ); intArray yValues = new intArray(); public PlotCanvas( Mandatory1 midlet ){ this.midlet = midlet; addCommand( exitCommand ); setCommandListener( this ); plot = new Plot("Mandatory #1", yValues.toArray(), this); } protected void paint( Graphics g ){ plot.draw(g); } public void commandAction( Command c, Displayable d ){ if( c == exitCommand ){ midlet.exit(); } } protected void keyPressed(int keyCode) { // supports game keys, navigator keys and numpad switch(keyCode) { case UP: // zoom in case NAV_UP: case KEY_NUM2: plot.zoomIn(); break; case LEFT: // move left case NAV_LEFT: case KEY_NUM4: plot.left(); break; case FIRE: // default view case NAV_SELECT: case KEY_NUM5: plot.center(); break; case RIGHT: // move right case NAV_RIGHT: case KEY_NUM6: plot.right(); break; case DOWN: // zoom out case NAV_DOWN: case KEY_NUM8: plot.zoomOut(); break; } //System.out.println("Key pressed: " + keyCode + " " + (char)keyCode); } }