J2ME (2) through game code

xiaoxiao2021-03-06  49

Assisted Cover Class

Package npc7776;

Import javax.microedition.lcdui. *;

Import java.util. *;

/ ************************************************

* Class function introduction: Start the display cover, called by the main class, the cover shows the two seconds

*************************************** /

Public Class Cover

Extends canvas {

Private Planemain MAINSCREEN = NULL;

PRIVATE TIMER TIMER = NULL;

Image img = null;

Public cover (Planemain M) {

MAINSCREEN = M;

Timer = new timer ();

Timertask TSK = New Timertask () {

Public void run () {

MAINSCREEN.GOBACK (); // Return to the main window

}

}

Timer.Schedule (TSK, 2000); // Note One

}

Public void paint (graphics g) {

Int width = getWidth ();

INT Height = GetHeight ();

G.SetColor (255, 255, 255);

g.fillRect (0, 0, width, height); // clear screen

Try {

IMG = image.createImage ("/ res / ca.png");

} catch (exception e) {}

g.drawImage (IMG, Width / 2, Height / 2, Graphics.hcenter | Graphics.vcenter);

} // Note Two

}

Note:

I. There is an inline Timertask in the construction class, and he completed the Run () method, when executed, the main body class is called

GOBACK () method, while Timer.Schedule (TSK, 2000) method execution results are executing Timertask after 2000 milliseconds

Object TSK's Run () method. About Timers in J2ME here again, in the J2ME, the timer is used for

In the specified time executing tasks or repeatedly performs tasks, support from MIDPv1.0 in J2ME provides support. want

Use timers to involve TIMER (Timer) classes and Timertask classes. Timertask class is a

Failure, for implementing a specific task. The Timer class is used to perform tasks represented by the Timertask object through regularity. want

With the timer function, you must have a new class from the Timertask class, and the Void Run () method is reloaded, then Timer is

The task is performed timed.

Two. We can see that Cover inherits Canvas, then actively performs the method when it constructs. His main purpose

It is to implement a picture to the display area. Here you introduce the image. Creating an Image object is not a way of constructing through an object,

Instead, to be implemented by calling the confine method of the Image class, if the image is created by the image file within the resource,

Then the image file format must be a PNG format, because only image resources in the PNG format are supported in the MIDP (support in MIDPv2.0

Transparent PNG image). The image resource is typically stored under the project / RES / below. Need to adjust when using Graphics to output images

The method is Void DrawImage (Image Img, Int X, Int Y, Int Anchor), in addition, Graphics in MIDPv2.0

The class also adds a new method for rotating the image, ie Void DrawRegion (Image IMG, INT X_SRC, INT Y_SRC, INT WIDTH, INTHEIGHT, INT TRANSFORM, INT X_DEST, INT Y, INT Y_DEST, INT Anchor, can be in the DrawRegion method

The rotating image is output without creating a new image object. Parameter Transform represents the way to rotate, allowing the value allowed

Sprite.Trans_none does not rotate

Sprite.trans_ROT90, SPRITE.TRANS_ROT180, SPRITE.TRANS_ROT270 clockwise 90, 180, 270

Sprite.Trans_Mirror flips along the horizontal line

Sprite.trans_mirror_rot90, sprite.trans_mirror_rot180, sprite.trans_mirror_rot270

Rotate 90 degrees, 180 degrees, 270 degrees clockwise after flipping along the horizontal line

转载请注明原文地址:https://www.9cbs.com/read-40739.html

New Post(0)