?? fullcanvastest.java
字號(hào):
import com.nokia.mid.ui.FullCanvas;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Random;
/**
* An example that demonstrates the use of the Nokia UI FullCanvas class.
* You must have the nokia UI class files on your classpath and run this example
* on a Nokia emulator (such as the 7210).
* @author Martin J. Wells
*/
public class FullCanvasTest extends MIDlet
{
private MyCanvas myCanvas;
/**
* An inner class which extends from the com.nokia.mid.ui.FullCanvas and
* implements a random rectangle drawer.
*/
class MyCanvas extends FullCanvas
{
private Random randomizer = new Random();
/**
* A method to obtain a random number between a miniumum and maximum
* range.
* @param min The minimum number of the range
* @param max The maximum number of the range
* @return
*/
private int getRand(int min, int max)
{
int r = Math.abs(randomizer.nextInt());
return (r % (max - min)) + min;
}
/**
* Canvas class paint implementation where we draw the some random
* rectangles.
* @param graphics The graphics context to draw to
*/
protected void paint(Graphics graphics)
{
for (int i = 10; i > 0; i--)
{
graphics.setColor(getRand(1, 254), getRand(1, 254), getRand(1, 254));
graphics.fillRect(0, 0, i * (getWidth() / 10), i * (getHeight() / 10));
}
}
}
/**
* MIDlet class which constructs an instance of our custom FullCanvas.
*/
public FullCanvasTest()
{
myCanvas = new MyCanvas();
}
/**
* Called by the Application Manager when the MIDlet is starting or resuming
* after being paused. In this example it acquires the current Display object
* and uses it to set the Form object created in the MIDlet constructor as
* the active Screen to display.
* @throws MIDletStateChangeException
*/
protected void startApp() throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(myCanvas);
}
/**
* Called by the MID's Application Manager to pause the MIDlet. A good
* example of this is when the user receives an incoming phone call whilst
* playing your game. When they're done the Application Manager will call
* startApp to resume. For this example we don't need to do anything.
*/
protected void pauseApp()
{
}
/**
* Called by the MID's Application Manager when the MIDlet is about to
* be destroyed (removed from memory). You should take this as an opportunity
* to clear up any resources and save the game. For this example we don't
* need to do anything.
* @param unconditional if false you have the option of throwing a
* MIDletStateChangeException to abort the destruction process.
* @throws MIDletStateChangeException
*/
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -