Activity 10.6 - Using low level interfaces

Topic

This exercise allows you to develop a MIDlet with a low level user interface.

Materials

You will make use of the MIDlets SimpleGraphics and class MyCanvas described in Unit 10.

The code for SimpleGraphics and MyCanvas has been added to this project as text files for you to amend.

Task

The MIDlet SimpleGraphics and its associated class MyCanvas, produces a simple circle on the screen which the user is able to move around. In this activity you will modify this MIDlet so that the circle moves continuously in the chosen direction rather than just one pixel. The circle then continues in this direction until one of the other arrow keys is selected. The circle will then move continuously in this new direction.

This is the basis of a number of simple computer games and in itself it can be considered a game with the object being to keep the circle on the screen. Further simple developments would be to add fixed objects to be avoided (or hit) or even an 'AI' driven opponent! You have already met the idea of collision detection in Unit 7.

Instructions

  1. Follow the instructions from Activity 4 to create a new project and a MIDlet called SimpleGraphics. The package should be named simplegraphics. You may want to copy the code of the MIDlet and the class MyCanvas in step 2 below from the text files provided.

  2. Add a class (not a MIDlet) MyCanvas to the project, making sure it is in the same package as the SimpleGraphics MIDlet, then compile and run the project.

  3. Alter the code in MyCanvas so as to cause the circle to keep moving in the direction which has been selected, until a different direction is pressed. Re-compile and run.