PaintCanvas.java


Back
/**
 * PaintCanvas.Java
 * @author j2meSalsa.com
 * This class shows you how things are drawn on to a canvas.
 */

package com.jme.canvas;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.List;

class PaintCanvas extends Canvas implements CommandListener{

	private Command backCommand = new Command("Back", Command.EXIT, 1);
	private List mainList;
	private Display display;

	PaintCanvas(List mainList, Display display){
    	this.mainList = mainList;
    	this.display = display;
		this.setTitle("Paint Me Black");
        this.addCommand(backCommand);
        this.setCommandListener(this);
	}
	/*
	 * Do all your drawings in this method
	 */
	public void paint(Graphics g) {
		g.setColor(0,0,0); // set Black Color for background
		g.fillRect(0,0,getWidth(),getHeight());
		g.setColor(225,225,225); // set White colour for preceding operations
		g.drawString("Width: " + getWidth(), 0, 0, Graphics.TOP|Graphics.LEFT);
		g.drawString("Height: " +  getHeight(), getWidth(), getHeight(), Graphics.BOTTOM|Graphics.RIGHT);
	}

	   /**
	    * Good ol' MIDlet event handling.
	    *
	    */
	   public void commandAction(Command cmd, Displayable disp) {
	       if (cmd == backCommand) {
	       	display.setCurrent(mainList);
	       }
	   }
}	

Back

This page is a part of a frames based web site. If you have landed on this page from a search engine click here to view the complete page.