Please take a look?

Hello :) My friend is doing his thesis & he's stuck with this program. Apparently it's not compiling. Unfortunately I don't have Java installed on this comp (in work) so I'm not much use but I was hoping someone here could point him in the right direction. Here goes...

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

Description: Basic paddle ball type game.

This example midlet demonstrates how to use threads and the Canvas class. It implements

a simple paddle ball type game. It demonstrates how to use a clipping region to implement

graphics more effeciently.

It should animate at a constant speed on all phones, although it may appear

jerky on devices with very restricted processing resources.

@createdden 21 mars 2002

COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.

The software is the copyrighted work of Sony Ericsson Mobile Communications AB.

The use of the software is subject to the terms of the end-user license

agreement which accompanies or is included with the software. The software is

provided "as is" and Sony Ericsson specifically disclaim any warranty or

condition whatsoever regarding merchantability or fitness for a specific

purpose, title or non-infringement. No warranty of any kind is made in

relation to the condition, suitability, availability, accuracy, reliability,

merchantability and/or non-infringement of the software provided herein.

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

package midp.demo;

import java.io.*;

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

/**

* Basic Ball and Paddle game. Use arrow keys to move paddle.

* Demonstrates multi-threading, animation, event handling.

*

* @see MIDlet

*/

public class PaddleBall extends MIDlet implements CommandListener {

/**

* Constant for white color

*/

private static final int COLOR_WHITE = 0xFFFFFF;

/**

* Constant for black color

*/

private static final int COLOR_BLACK = 0x000000;

/**

* The game speed (in milliseconds)

*/

private final int GAME_SPEED = 5;

/**

* The main game screen

*/

private GameFrame mainFrame;

/**

* The title screen

*/

private Form titleScreen;

/**

* The results screen

*/

private Form statsScreen;

/**

* The number of milliseconds the user has been playing this game

*/

private long elapsedTime;

/**

* The ball object for this game

*/

private Ball myBall;

/**

* The paddle object for this game

*/

private Paddle myPaddle;

/**

* True if game has not started or player lost

*/

private boolean gameOver = true;

/**

* How many games have been played

*/

private int numGames;

/**

* Reference to Display

*/

private Display myDisplay;

public PaddleBall() {

myDisplay = Display.getDisplay(this);

/*

* Create main game screen

*/

mainFrame = new GameFrame();

/*

* Create title screen

*/

titleScreen = new Form("Paddle Ball");

titleScreen.append(new StringItem(null,

"The classic arcade game, now on your mobile device!"));

titleScreen.setCommandListener(this);

titleScreen.addCommand(new Command("START", Command.OK, 1));

/*

* Create results screen

*/

statsScreen = new Form("Results");

statsScreen.setCommandListener(PaddleBall.this);

statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));

}

/**

* Begin the application, show its frame

*/

protected void startApp() {

myDisplay.setCurrent(titleScreen);

}

/**

* Application is being terminated, kill threads

*/

protected void pauseApp() {

gameOver = true;

myBall = null;

myPaddle = null;

}

/**

* Clean up application

*/

protected void destroyApp(boolean unconditional) {

gameOver = true;

}

/**

* Start the game

*/

public void commandAction(Command c, Displayable d) {

/*

* Create ball and paddle threads

*/

myBall = new Ball();

myPaddle = new Paddle();

/*

* Get the starting time

*/

elapsedTime = System.currentTimeMillis();

/*

* Set the initial ball and paddle positions

*/

myBall.setUp();

myPaddle.setUp();

/*

* Set the screen

*/

myDisplay.setCurrent(mainFrame);

/*

* Start the thread

*/

gameOver = false;

myBall.start();

myPaddle.start();

}

/**

* The main Screen for this game

*/

class GameFrame extends Canvas {

/**

* Canvas receives all key events

*/

public void keyPressed(int keyCode) {

int gameAction = 0;

try {

gameAction = getGameAction(keyCode);

} catch (Exception e) {

}

if (gameAction == LEFT) {

myPaddle.move(-2 * GAME_SPEED);

} else if (gameAction == RIGHT) {

myPaddle.move(2 * GAME_SPEED);

}

return;

}

/**

* Clear the game screen

*/

private void clear(Graphics g) {

g.setColor(0xFFFFFF);

g.fillRect(0, 0, getWidth(), getHeight());

}

/**

* Paint the game screen

*/

public void paint(Graphics g) {

synchronized (g) {

/*

* Clear the screen

*/

clear(g);

g.setColor(0x000000);

/*

* Paint the ball and paddle

*/

g.fillRect(myPaddle.x, myPaddle.y, myPaddle.WIDTH,

myPaddle.HEIGHT);

g.fillArc(myBall.x, myBall.y, myBall.SIZE,

myBall.SIZE, 0, 360);

}

}

}

/**

* The ball thread

*/

class Ball extends Thread {

/**

* The ball diameter

*/

public final int SIZE = mainFrame.getHeight() / 15;

/**

* The sign of the x component of the velocity

*/

private int xDir = 1;

/**

* The sign of the y component of the velocity

*/

private int yDir = 1;

/**

* X position of ball

*/

int x;

/**

* Y position of ball

*/

int y;

/**

* Create a ball

*/

public Ball() {

setUp();

}

/**

* Set starting position

*/

void setUp() {

x = mainFrame.getWidth() / 2;

y = mainFrame.getHeight() / 10;

}

/**

* Loop to run thread, loops until game over

*/

public void run() {

while (!gameOver) {

/*

* Sleep for animation delay

*/

try {

Thread.sleep(150 - 10 * GAME_SPEED);

} catch (Exception e) {

return;

}

int oldX = x;

int oldY = y;

/*

* Recalculate x position

*/

int xPos = x + xDir * GAME_SPEED;

if (((xPos+SIZE) <= mainFrame.getWidth())

&& (xPos >= 0)) {

x = xPos;

} else {

xDir *= -1;

AlertType.WARNING.playSound(myDisplay);

}

/*

* Recalculate y position

*/

int yPos = y + yDir * GAME_SPEED;

if ((yPos >= 0) &&

((yPos + SIZE) <=

(mainFrame.getHeight() - myPaddle.HEIGHT))) {

y = yPos;

} else if ((yPos + SIZE) >

(mainFrame.getHeight() - myPaddle.HEIGHT)) {

/*

* Bounce off paddle

*/

if ((xPos <= (myPaddle.x + myPaddle.WIDTH))

&& ((xPos + SIZE) >= myPaddle.x)) {

yDir *= -1;

AlertType.INFO.playSound(myDisplay);

/*

* Player loses

*/

} else {

gameOver = true;

/*

* Get statistic information

*/

elapsedTime = System.currentTimeMillis()

- elapsedTime;

numGames++;

statsScreen.append(new StringItem("Game " +

numGames + " over", "Time: " +

(elapsedTime/1000) + " seconds"));

/*

* Show the statistics screen

*/

myDisplay.setCurrent(statsScreen);

return;

}

} else if (yPos < 0) {

yDir *= -1;

AlertType.WARNING.playSound(myDisplay);

}

mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),

Math.abs(x-oldX) + SIZE,

Math.abs(y-oldY) + SIZE);

}

}

}

/**

* The game paddle thread

*/

class Paddle extends Thread {

/**

* Paddle width

*/

public final int WIDTH = mainFrame.getWidth() / 6;

/**

* Paddle height

*/

public final int HEIGHT = mainFrame.getHeight() / 15;

/**

* X position

*/

int x;

/**

* Y position

*/

int y;

/**

* Create a new paddle

*/

public Paddle() {

setUp();

}

/**

* Initialize starting position

*/

void setUp() {

x = mainFrame.getWidth() / 2 - WIDTH / 2;

y = mainFrame.getHeight() - HEIGHT;

}

/**

* Loop to run paddlethread, loops until game over

*/

public void run() {

while (!gameOver) {

try {

Thread.sleep(10);

} catch (Exception e) {

return;

}

}

}

/**

* Move paddle right/left

*/

void move(int delta) {

int oldX = x;

int xPos = x + delta;

if (((xPos + WIDTH) <= mainFrame.getWidth())

&& (xPos >= 0)) {

x = xPos;

}

mainFrame.repaint(Math.min(oldX, x), y,

Math.abs(x-oldX) + WIDTH, HEIGHT);

}

}

}

[9913 byte] By [karry1412a] at [2007-11-27 0:57:24]
# 1
Cross-post http://forum.java.sun.com/thread.jspa?threadID=5160243&tstart=0
karma-9a at 2007-7-11 23:30:55 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...