Hi there,
I have an assignment due in a couple of days and I need some help. I don't have time to read a Java books. Plus, my teacher is useless as he can't explain anything...and the TAs are worst. My error is in line 145 (scroll down) saying "illegal start of expression". I didn't have this error before I added the movement command. Any help is greatly appreciated :)

-------------------------------

import java.awt.*;
import java.applet.*;


/* Part 0, CSC104 Assignment 2 Fall 08
* Where is Wall-e? */
public class Part5 extends Applet implements Runnable{



private Location ovalOffset;
private Location pictureLocation;
private Color color;
private Oval oval;
private Size size;


private Location ovalOffset2;
private Color color2;
private Oval oval2;
private Size size2;


private Box neck;
private Location neckOffset;
private Color neckColor;
private Size neckSize;


private Square bot;
private Location botOffset;
private Color botColor;
private Size botSize;


private Oval eye;
private Location eyeOffset;
private Color eyeColor;
private Size eyeSize;


private Oval eyes;
private Location eyesOffset;
private Color eyesColor;
private Size eyesSize;


private Oval wheel;
private Location wheelOffset;
private Color wheelColor;
private Size wheelSize;


private Oval wheels;
private Location wheelsOffset;
private Color wheelsColor;
private Size wheelsSize;


int x=20;
int y=10;
Thread appletThread;


/* Initialize variables for an oval. */
public void init() {


pictureLocation = new Location(0, 0);
ovalOffset = new Location(0, 0);
color = new Color(0, 0, 0);
size = new Size(100, 200);
oval = new Oval(pictureLocation, ovalOffset, size, color);



ovalOffset2 = new Location(10,10);
color2 = new Color(255, 255, 255);
size2 = new Size(80, 180);
oval2 = new Oval(pictureLocation, ovalOffset2, size2, color2);


neckOffset = new Location(87, 100);
neckColor = new Color(0, 102, 92);
neckSize = new Size(115, 22);
neck = new Box(pictureLocation, neckOffset, neckSize, neckColor);


botOffset = new Location(0, 200);
botColor = new Color(181, 84, 0);
botSize = new Size(200, 200);
bot = new Square(pictureLocation, botOffset, botSize, botColor);


eyeOffset = new Location(50, 10);
eyeColor = new Color(0, 0, 0);
eyeSize = new Size(80, 80);
eye = new Oval(pictureLocation, eyeOffset, eyeSize, eyeColor);


eyesOffset = new Location(90,10 );
eyesColor = new Color(0, 0, 0);
eyesSize = new Size(80, 80);
eyes = new Oval(pictureLocation, eyesOffset, eyesSize, eyesColor);


wheelOffset = new Location(0,355 );
wheelColor = new Color(0, 0, 0);
wheelSize = new Size(98, 98);
wheel = new Oval(pictureLocation, wheelOffset, wheelSize, wheelColor);


wheelsOffset = new Location(100,355 );
wheelsColor = new Color(0, 0, 0);
wheelsSize = new Size(98, 98);
wheels = new Oval(pictureLocation, wheelsOffset, wheelsSize, wheelsColor);


if(appletThread == null)
{
appletThread = new Thread(this);
appletThread.start();
}
}
public void start() {
}


public void stop() {
}
public void destroy() {


if(appletThread != null){
appletThread.stop();
appletThread = null;
}
}
public void run(){
int Y = 20;
boolean move_down=true;
int Vertical_Count=0;
while(true)
{
//Sample code for movement
if(Vertical_Count == 200) move_down = false;
if(vertical_Count == 0) move_down = true;
if(move_right) {
Y+=1; //Y++; Y=Y+1
Vertical_Count++;
}
else{
Y-=1; //Y--; Y=Y-1
Vertical_Count--;
}
pictureLocation = new Location(X, Y);
oval = new Oval(pictureLocation, ovalOffset, size, color);
oval2 = new Oval(pictureLocation, ovalOffset2, size2, color2);
neck = new Box(pictureLocation, neckOffset, neckSize, neckColor);
eye = new Oval(pictureLocation, eyeOffset, eyeSize, eyeColor);
eyes = new Oval(pictureLocation, eyesOffset, eyesSize, eyesColor);
repaint();
try{Thread.sleep(100);}
catch(InterruptedException e){System.exit(1);}


/* Paint an oval */
public void paint(Graphics g) {                              ---ERROR LINE
oval.paint(g);
oval2.paint(g);
neck.paint(g);
bot.paint(g);
eye.paint(g);
eyes.paint(g);
wheel.paint(g);
wheels.paint(g);
}
;}
}
}

Recommended Answers

All 4 Replies

Please use code-tags and proper indentation.

I believe you meant to close your while loop and your run method before overriding paint--

import java.awt.*;
import java.applet.*;

/* Part 0, CSC104 Assignment 2 Fall 08
* Where is Wall-e? */
public class Part5 extends Applet implements Runnable{


	private Location ovalOffset;
	private Location pictureLocation;
	private Color color;
	private Oval oval;
	private Size size;

	private Location ovalOffset2;
	private Color color2;
	private Oval oval2;
	private Size size2;

	private Box neck;
	private Location neckOffset;
	private Color neckColor;
	private Size neckSize;

	private Square bot;
	private Location botOffset;
	private Color botColor;
	private Size botSize;

	private Oval eye;
	private Location eyeOffset;
	private Color eyeColor;
	private Size eyeSize;

	private Oval eyes;
	private Location eyesOffset;
	private Color eyesColor;
	private Size eyesSize;

	private Oval wheel;
	private Location wheelOffset;
	private Color wheelColor;
	private Size wheelSize;

	private Oval wheels;
	private Location wheelsOffset;
	private Color wheelsColor;
	private Size wheelsSize;

	int x=20;
	int y=10;
	Thread appletThread;

	/* Initialize variables for an oval. */
	public void init() {

		pictureLocation = new Location(0, 0);
		ovalOffset = new Location(0, 0);
		color = new Color(0, 0, 0);
		size = new Size(100, 200);
		oval = new Oval(pictureLocation, ovalOffset, size, color);


		ovalOffset2 = new Location(10,10);
		color2 = new Color(255, 255, 255);
		size2 = new Size(80, 180);
		oval2 = new Oval(pictureLocation, ovalOffset2, size2, color2);

		neckOffset = new Location(87, 100);
		neckColor = new Color(0, 102, 92);
		neckSize = new Size(115, 22);
		neck = new Box(pictureLocation, neckOffset, neckSize, neckColor);

		botOffset = new Location(0, 200);
		botColor = new Color(181, 84, 0);
		botSize = new Size(200, 200);
		bot = new Square(pictureLocation, botOffset, botSize, botColor);

		eyeOffset = new Location(50, 10);
		eyeColor = new Color(0, 0, 0);
		eyeSize = new Size(80, 80);
		eye = new Oval(pictureLocation, eyeOffset, eyeSize, eyeColor);

		eyesOffset = new Location(90,10 );
		eyesColor = new Color(0, 0, 0);
		eyesSize = new Size(80, 80);
		eyes = new Oval(pictureLocation, eyesOffset, eyesSize, eyesColor);

		wheelOffset = new Location(0,355 );
		wheelColor = new Color(0, 0, 0);
		wheelSize = new Size(98, 98);
		wheel = new Oval(pictureLocation, wheelOffset, wheelSize, wheelColor);

		wheelsOffset = new Location(100,355 );
		wheelsColor = new Color(0, 0, 0);
		wheelsSize = new Size(98, 98);
		wheels = new Oval(pictureLocation, wheelsOffset, wheelsSize, wheelsColor);

		if(appletThread == null){

			appletThread = new Thread(this);
			appletThread.start();
		}
	}

	public void start(){}

	public void stop(){}

	public void destroy() {

		if(appletThread != null){

			appletThread.stop();
			appletThread = null;
		}
	}

	public void run(){

		int Y = 20;
		boolean move_down=true;
		int Vertical_Count=0;

		while(true){
			//Sample code for movement
			if(Vertical_Count == 200)
				move_down = false;
			if(vertical_Count == 0)
				move_down = true;
			if(move_right){
				Y+=1; //Y++; Y=Y+1
				Vertical_Count++;
			}else{
				Y-=1; //Y--; Y=Y-1
				Vertical_Count--;
			}
		
			pictureLocation = new Location(X, Y);
			oval = new Oval(pictureLocation, ovalOffset, size, color);
			oval2 = new Oval(pictureLocation, ovalOffset2, size2, color2);
			neck = new Box(pictureLocation, neckOffset, neckSize, neckColor);
			eye = new Oval(pictureLocation, eyeOffset, eyeSize, eyeColor);
			eyes = new Oval(pictureLocation, eyesOffset, eyesSize, eyesColor);
			repaint();
	
			try{
				Thread.sleep(100);
			}
			catch(InterruptedException e){
				System.exit(1);
			}
		}	// body of while loop (I'm assuming);
	}	// Close the body of the run method

	/* Paint an oval */
	public void paint(Graphics g) { //---ERROR LINE
		oval.paint(g);
		oval2.paint(g);
		neck.paint(g);
		bot.paint(g);
		eye.paint(g);
		eyes.paint(g);
		wheel.paint(g);
		wheels.paint(g);
	}

//	;}
//	}
}

Thanks :):)

However, I can't get the oval, oval2, neck, eye, eyes to move up and down. I'm using the code my instructor gave me and it isn't that helpufl :S

Thanks :):)

However, I can't get the oval, oval2, neck, eye, eyes to move up and down. I'm using the code my instructor gave me and it isn't that helpufl :S

It's considered bad form to post verbatim threads on two separate forums at the same time. Read post 4 on the other forum, in particular. It may well be true that your instructors/T.A.'s aren't very good, but generally it's a bad idea to mention it, as well as mentioning that you don't have time to read the book. Saying you can't get something to work also doesn't help much, particularly since you haven't posted the revised code.

Close this thread or the other thread on the other forum, ask a more specific question, and don't wait till a few days before it's due next time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.