..


Sponsored Links

Create a simple graphic animation with Java ME

Article written by Antonio Coschignano
Page 1 of 4

An essential feature of development-oriented platforms to mobile devices is to provide extensible model for the production of animated graphics principalmene usually aimed at the creation of video games.

In Java ME, this is implemented through a specification that also includes the management of the life cycle of a game. We will ignore for the moment this issue for the 'overall architecture for the development of the game itself, and Let's go hand in what concerns the animated graphics that are in my opinion the most creative and interesting.

Display, Displayable and Canvas

The heart of the graphics library in Java ME classes Display and Displayable . The first handles the elements displayed on the screen of the device and the second represents the highest abstraction of these elements, components that are displayed and positioned to 'internal screen.
In this context, the Java ME provides two types of Displayable objects each of which has a different role according to the components that we intend to build or use. The subclasses of Displayable are fundamental:

The Screen class defines high-level graphical components, which are structures or predefined graphical controls such as Form, Alert, TextBox, in turn subclasses of Screen and directly usable.

The Canvas class instead they implement the Displayable class, but in turn needs a further concretization of the abstract method paint ( Graphics g) where to 'interior is necessary to define the directions of a design to be projected on the screen. This means low-level graphical programming necessary for realizazzione animations. Of particular importance is the 'Graphics object to be used in the paint method. This object provides methods for drawing basic low-level, with which you can draw lines, circles, figures, points etc. ..
We see the main methods:

  • void drawLine (int x1, int y1, int x2, int y2):
    Draw a line through the points (x1, y1), (x2, y2)
  • void drawRect (int x, int y, int width, int height)
    Draw a rectangle with coordinates (x1, y1) with respective height and width
  • filRect void (int x, int y, int width, int height)
    As above, Solta that fills the rectangle with the current color
  • drawArc void (int x, int y, int width, int height, int startAngle, int arcAngle)
    Draw a 'bow with its coordinates x1 and y1, height, width (height and width) and width of the' corner
  • void setColor (int r, int g, int b)
    Sets the current color with which the figures are then drawn
The Canvas class also contains methods to notify events operated by pressing the buttons on the keypad of the device (keyPressed (), etc. keyRleased.), And events related to other pointing devices (pinterDragged (), pointerPressed () etc...)

Once materialized, which is a Displayable object of type Canvas or a screen should display on the screen. To this proprosito comes in the 'object Diaplay which deals to manage the display of elements on the screen. The 'Display object as a singleton , it is not instantiated directly, but you can get a 'request in this way:






 public class Demo extends MIDlet {





  



 private Display display;



  



 ...



  



 display = Display.getDisplay (this);



  



 ...







 }



Once you have here is an instance of the main methods we can use:
  • public Displayable GetCurrent (), returns to the 'graphic object displayed on the screen
  • public void setCurrent (Displayable d) sets the 'object to display
All those classes are part of the package javax.microedition.lcdui.

In the same category ...
E-Learning
AutoCAD (eBook) AutoCAD (eBook)
Creation of architectural structures. At only 29 €.
VB.NET (Course) VB.NET (Course)
Make Desktop Applications with Visual Basic.. From 49 €.
Webmaster Advanced (Course) Webmaster Advanced (Course)
Become a professional Webmaster. From 39 €.
Sponsored Links