import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
import net.jscience.math.kvm.MathFP;
/**
* A MIDlet demonstrating how to read and interpret key events from a device.
* @author Martin J. Wells
*/
public class mamal extends MIDlet implements CommandListener
{
private MyCanvas myCanvas;
private Command quit;
private Timer timer;
private PrintTask task;
public double x = 0; // current position
public double y = 0;
public int l = 10 ;
public double gas = 0.1 ;
public double alfa =0 ;
public double ax = 0;
public double ay = 0;
public double vx = 0;
public double vy = 0;
/**
* A custom Canvas class we use to draw a string based on a screen
* position modified by key events.
*/
class MyCanvas extends Canvas
{
private String lastKeyName = "Hit a Key"; // name of the last key they hit
/**
* Overriden Canvas.paint method that draws a string at the current
* position (x, y).
* @param graphics The graphics context for this Canvas
*/
protected void paint(Graphics graphics)
{
// draw a black rectangle the size of the screen in order to wipe
// all previous contents
graphics.setColor(255, 255, 255);
graphics.fillRect(0, 0, getWidth(), getHeight());
// draw the string (the name of the last key that was hit)
graphics.setColor(0, 0, 0);
graphics.drawLine( MathFP.toInt(x),MathFP.toInt(y),MathFP.toInt(y),Ma thFP.toInt(x));
}
/**
* Overriden Canvas method called when a key is pressed on the MID. This
* method sets the key name string and then modifies the position if a
User Interface (LCDUI) 169
* directional key was hit.
* @param keyCode the code of the key that was pressed
*/
protected void keyPressed(int keyCode)
{
if (keyCode > 0)
lastKeyName = getKeyName(keyCode);
switch (getGameAction(keyCode))
{
case UP: gas = gas + 0.1; break;
case DOWN: gas = gas - 0.1; break;
case RIGHT: alfa = alfa + 0.1; break;
case LEFT: alfa = alfa - 0.1; break;
}
// request a repaint of the canvas
repaint();
}
}
/**
* MIDlet constructor that creates the custom canvas (MyCanvas) and adds
* a quit command to it.
*/
public mamal()
{
// Construct a the canvas
timer = new Timer();
task = new PrintTask();
myCanvas = new MyCanvas();
// we still need a way to quit
quit = new Command("Quit", Command.EXIT, 2);
myCanvas.addCommand(quit);
myCanvas.setCommandListener(this);
}
/**
* 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
{
// upon starting up we display the canvas
timer.schedule(task, 1000, 1000);
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()
{
task.cancel();
}
/**
* 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
{
timer.cancel();
}
/**
* The CommandListener interface method called when the user executes a
* Command, in this case it can only be the quit command we created in the
* constructor and added to the Canvas.
* @param command
* @param displayable
*/
public void commandAction(Command command, Displayable displayable)
{
try
{
if (command == quit)
{
destroyApp(true);
notifyDestroyed();
}
//User Interface (LCDUI) 171
}
catch (MIDletStateChangeException me)
{
System.out.println(me + " caught.");
}
}
class PrintTask extends TimerTask
{
/**
* To implement a task you need to override the run method.
*/
public void run()
{
// output the time the task ran at
ax = mamal.MathFP.sin(alfa) * gas;
ay = mamal.MathFP.cos(alfa) * gas;
x = x + vx;
y = y + vy;
vx = vx * 7 / 10;
vy = vy * 7 / 10;
vx = vx + ax;
vy = vy + ay;
//LINE (x + l * SIN(alfa), y + l * COS(alfa))-(x - l * SIN(alfa), y - l * COS(alfa))
}
}
}
Project "mamal" loaded
Project settings saved
Building "mamal"
h:\WTK22\apps\mamal\src\mamal.java
.gif)
package net.jscience.math.kvm does not exist
import net.jscience.math.kvm.MathFP;
^
h:\WTK22\apps\mamal\src\mamal.java:56: cannot find symbol
symbol : variable MathFP
location: class mamal.MyCanvas
graphics.drawLine( MathFP.toInt(x),MathFP.toInt(y),MathFP.toInt(y),Ma thFP.toInt(x));
^
h:\WTK22\apps\mamal\src\mamal.java:56: cannot find symbol
symbol : variable MathFP
location: class mamal.MyCanvas
graphics.drawLine( MathFP.toInt(x),MathFP.toInt(y),MathFP.toInt(y),Ma thFP.toInt(x));
^
h:\WTK22\apps\mamal\src\mamal.java:56: cannot find symbol
symbol : variable MathFP
location: class mamal.MyCanvas
graphics.drawLine( MathFP.toInt(x),MathFP.toInt(y),MathFP.toInt(y),Ma thFP.toInt(x));
^
h:\WTK22\apps\mamal\src\mamal.java:56: cannot find symbol
symbol : variable MathFP
location: class mamal.MyCanvas
graphics.drawLine( MathFP.toInt(x),MathFP.toInt(y),MathFP.toInt(y),Ma thFP.toInt(x));
^
h:\WTK22\apps\mamal\src\mamal.java:164: cannot find symbol
symbol : variable MathFP
location: class mamal
ax = mamal.MathFP.sin(alfa) * gas;
^
h:\WTK22\apps\mamal\src\mamal.java:165: cannot find symbol
symbol : variable MathFP
location: class mamal
ay = mamal.MathFP.cos(alfa) * gas;
^
7 errors
com.sun.kvem.ktools.ExecutionException
Build failed