Can't get an Applet working

Trouble transferring from JCreator to the web

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

39 Replies - 2671 Views - Last Post: 11 June 2009 - 08:58 PM Rate Topic: -----

#1 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Can't get an Applet working

Posted 10 June 2009 - 04:16 PM

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

class MovingImage
{
	private Image image;		//The picture
	private double x;			//X position
	private double y;			//Y position
	
	//Construct a new Moving Image with image, x position, and y position given
	public MovingImage(Image img, double xPos, double yPos)
	{
		image = img;
		x = xPos;
		y = yPos;
	}
	
	//Construct a new Moving Image with image (from file path), x position, and y position given
	public MovingImage(String path, double xPos, double yPos)
	{
		this(new ImageIcon(path).getImage(), xPos, yPos);	
	}
	
	public void setPosition(double xPos, double yPos)
	{
		x = xPos;
		y = yPos;
	}
	
	public void setImage(String path)
	{
		image = new ImageIcon(path).getImage();
	}
	
	public void setY(double newY)
	{
		y = newY;
	}
	
	public void setX(double newX)
	{
		x = newX;
	}
	
	public double getX()
	{
		return x;
	}
	
	public double getY()
	{
		return y;
	}
	
	public Image getImage()
	{
		return image;
	}
}

class Rec
{
	private MovingImage image;
	private int height;
	public Rec(MovingImage i, int newHeight)
	{
		image = i;
		height = newHeight;
	}
	
	public MovingImage getImage()
	{
		return image;
	}
	
	public int getHeight()
	{
		return height;
	}
}

class ImagePanel extends JPanel {

	  private Image background; //The background image
	  private ArrayList<Rec> top;	//An array list of foreground images
	private ArrayList<Rec> bottom;
	private ArrayList<Rec> middle;
	private MovingImage copter;
	private ArrayList<MovingImage> smoke;
	
	//Constructs a new ImagePanel with the background image specified by the file path given
	  public ImagePanel(String img) 
	  {
		  this(new ImageIcon(img).getImage());
	  }

	//Constructs a new ImagePanel with the background image given
	  public ImagePanel(Image img)
	  {
		background = img;
		Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		
		top = new ArrayList<Rec>();
		middle = new ArrayList<Rec>();
		bottom = new ArrayList<Rec>();
		
		smoke = new ArrayList<MovingImage>();
	  }

	//called through repaint()
	  public void paintComponent(Graphics g) 
	  {
		  //Paint the background
		g.drawImage(background, 0, 0, null); 
		//Paint all other images on top of it
		for(Rec img : top)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(Rec img : middle)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(Rec img : bottom)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(MovingImage img : smoke)
			g.drawImage(img.getImage(), (int)(img.getX()), (int)(img.getY()), null);
		if(copter != null)
			g.drawImage(copter.getImage(), (int)(copter.getX()), (int)(copter.getY()), null);
		drawStrings(g);
	  }
 	
 	//draws various strings on the screen
 	public void drawStrings(Graphics g)
 	{
 		g.setFont(new Font("Arial",Font.BOLD,20));
		g.drawString("Distance: " + HelicopterForm.distance,30,500);
		g.setFont(new Font("Arial",Font.BOLD,20));
		if (HelicopterForm.distance > HelicopterForm.maxDistance)
			g.drawString("Best: " + HelicopterForm.distance,650,500);
		else
			g.drawString("Best: " + HelicopterForm.maxDistance,650,500);
		if(HelicopterForm.paused && !HelicopterForm.crashed)
		{
				g.setColor(Color.WHITE);
				g.setFont(new Font("Chiller",Font.BOLD,72));
				g.drawString("Paused",325,290);
				g.setFont(new Font("Chiller",Font.BOLD,30));
				g.drawString("Click to unpause.",320,340);
		}
		if(!HelicopterForm.started)
		{
			g.setColor(Color.WHITE);
			g.setFont(new Font("Chiller",Font.BOLD,72));
			g.drawString("Helicopter Game",205,220);
			g.setFont(new Font("Chiller",Font.BOLD,50));
			g.drawString("Click to Start",320,310);
		}
 	}
 	
	  //Calls paintComponent with updated images
	  public void updateImages(ArrayList<Rec> newTop,ArrayList<Rec> newMiddle,ArrayList<Rec> newBottom,MovingImage newCopter,ArrayList<MovingImage> newSmoke)
	  {
		  top = newTop;
		  copter = newCopter;
		  middle = newMiddle;
		  bottom = newBottom;
		  smoke = newSmoke;
		  repaint();	//Repaints the frame
	  }
}



public class HelicopterForm extends Applet implements MouseListener
{
	private JFrame background;
	private ImagePanel back;
	
	public static boolean paused;
	public static boolean crashed;
	public static boolean started;
	public static boolean playedOnce;	
	
	public boolean goingUp;
	private double upCount;
	
	public static int distance;
	public static int maxDistance;
	
	public final int XPOS;
	public final int NUMRECS;
	public final int RECWIDTH;
	
	public int recheight;
	public String imageName;
	
	private int moveIncrement;
	private int numSmoke;
	
	private ArrayList<Rec> toprecs;
	private ArrayList<Rec> bottomrecs;
	private ArrayList<Rec> middlerecs;
	private ArrayList<MovingImage> smoke;
	private MovingImage helicopter;
	
	/*Graphics information:
	 *Background is 812 x 537
	 *Floor is 74 and Ceiling is 72 pixels high
	 *28 rectangles across that are 29 x 73
	 */
	
	public HelicopterForm()
	{
		NUMRECS = 28; //Number of bottom/top recs
		RECWIDTH = 29; //Width of all recs
		XPOS = 200; //X position of helicopter
		playedOnce = false; //checks for the first playthrough
		maxDistance = 0; //Sets the high score to 0
		
		initiate(); //Initiates the game
	}
	
	public void initiate()
	{
		if(!playedOnce) //if first play through
		{
			background = new JFrame("Helicopter Game"); 
			background.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //closes the program when the window is closed
			background.setResizable(false); //don't allow the user to resize the window
			background.setSize(new Dimension(818,568));
			background.setVisible(true);
			
			back = new ImagePanel("Images\\back.JPG");
			background.add(back); //puts the background image in the background of the frame
			back.addMouseListener(this);
			
			playedOnce = true;
		}
		//initialize various booleans
		goingUp = false; //helicopter going up or down
		paused = false; //game paused or not
		crashed = false; //helicopter crashed or not
		started = false; //game started or not
		
		distance = 0;
		upCount = 0;
		
		recheight = 73; //initial rec height
		imageName = "Images\\rec2.JPG";
		
		moveIncrement = 2;
		numSmoke = 15; //number of smoke bubbles
		
		toprecs = new ArrayList<Rec>();
		middlerecs = new ArrayList<Rec>();
		bottomrecs = new ArrayList<Rec>();
		smoke = new ArrayList<MovingImage>();
		
		helicopter = new MovingImage("Images\\helicopter.GIF",XPOS,270);
		
		//initialize the rectangle arrays
		for(int x = 0; x < NUMRECS; x++)
			toprecs.add(new Rec(new MovingImage(imageName,RECWIDTH*x,30),recheight));
		for(int x = 0; x < NUMRECS; x++)
			bottomrecs.add(new Rec(new MovingImage(imageName,RECWIDTH*x,450),recheight));
			
		middlerecs.add(new Rec(new MovingImage("Images\\rec2.JPG",1392,randomMidHeight()),73));
		middlerecs.add(new Rec(new MovingImage("Images\\rec2.JPG",1972,randomMidHeight()),73));
	
		drawRectangles();
	}
	
	public void drawRectangles()
	{
		long last = System.currentTimeMillis();
		long lastCopter = System.currentTimeMillis();
		long lastSmoke = System.currentTimeMillis();
		double lastDistance = (double)System.currentTimeMillis();
		
		int firstUpdates = 0;
		
		while(true)
		{
			//score increased by time rather than rectangles passed
			if(!paused && !crashed && started && (double)System.currentTimeMillis() - (double)(2900/40) > lastDistance)
			{	
				lastDistance = System.currentTimeMillis();
				distance++;
			}	
			
			//middle rectangles and helicopter updated every 10 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 10 > lastCopter)
			{
				lastCopter = System.currentTimeMillis();
				updateCopter();
				updateMiddle();
			}
			
			//top and bottom rectangles updated every 100 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 100 > last)
			{
				last = System.currentTimeMillis();
				updateRecs();
			}
			
			//smoke behind helicopter updated every 75 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 75 > lastSmoke)
			{
				lastSmoke = System.currentTimeMillis();
				if (firstUpdates < numSmoke)
				{
					firstUpdates++;
					smoke.add(new MovingImage("Images\\smoke.GIF",187,helicopter.getY()));
					for(int x = 0; x < firstUpdates; x++)
						smoke.set(x,new MovingImage("Images\\smoke.GIF",smoke.get(x).getX() - 12, smoke.get(x).getY()));
				}
				else
				{
					for(int x = 0; x < numSmoke - 1; x++)
						smoke.get(x).setY(smoke.get(x+1).getY());
					smoke.set(numSmoke - 1,new MovingImage("Images\\smoke.GIF",187,helicopter.getY()));
				}
					}
					back.updateImages(toprecs,middlerecs,bottomrecs,helicopter,smoke);
				}
	}
	
	//finishes the smoke animation after a crash
	public void finishSmoke()
	{
		long lastSmoke = System.currentTimeMillis();
		long lastSmoke2 = lastSmoke;
		while(System.currentTimeMillis() - 3000 < lastSmoke2)
		{
			if(System.currentTimeMillis() - 75 > lastSmoke)
			{
				lastSmoke = System.currentTimeMillis();
				for(int x = 0; x < smoke.size(); x++)
						smoke.get(x).setX(smoke.get(x).getX() - 12);
			}
			back.updateImages(toprecs,middlerecs,bottomrecs,helicopter,smoke);
		}
	}
	
	//updates the top and bottom rectangles' positions
	public void updateRecs()
	{
		for(int x = 0; x < (NUMRECS - 1); x++) //move all but the last rectangle 1 spot to the left
		{
			toprecs.set(x,new Rec(new MovingImage(toprecs.get(x+1).getImage().getImage(),RECWIDTH*x,toprecs.get(x+1).getImage().getY()),recheight));
			bottomrecs.set(x,new Rec(new MovingImage(bottomrecs.get(x+1).getImage().getImage(),RECWIDTH*x,bottomrecs.get(x+1).getImage().getY()),recheight));
		}
		lastRec();
	}
	
	//places the last rectangle in the array with a lot of randomization
	public void lastRec()
	{
		if(distance % 400 == 0)
			moveIncrement++;
		if(distance % 500 == 0 && recheight != 153)
		{
			recheight += 20; //makes the game more difficult
			if(recheight == 93)
				imageName = "Images\\rec3.JPG";
			else if(recheight == 113)
				imageName = "Images\\rec4.JPG";
			else if(recheight == 133)
				imageName = "Images\\rec5.JPG";
			else
				imageName = "Images\\rec6.JPG";
		}
		if(toprecs.get(NUMRECS - 1).getImage().getY() < 2) //if too high, move down
			moveDown();
		else if (bottomrecs.get(NUMRECS - 1).getImage().getY() > 463) //else if too low, move up
			moveUp();
		else //else move randomly
		{
			if((int)(Math.random() * 30) == 20)
				randomMove();
			else
			{
				if((int)(Math.random() * 2) == 1)
					moveUp();
				else
					moveDown();
			}
		}
	}
	
	//3 movement methods for the last rectangle
	public void randomMove()
	{
		if(Math.random() < .5)
		{
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS-1),toprecs.get(NUMRECS - 1).getImage().getY() + (463 - bottomrecs.get(NUMRECS - 1).getImage().getY())),recheight));
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),463),recheight));
		}
		else
		{
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() - (0 + toprecs.get(NUMRECS - 1).getImage().getY())),recheight));
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS-1),0),recheight));
		}
	}
	
	public void moveDown()
	{
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),toprecs.get(NUMRECS - 1).getImage().getY() + moveIncrement),recheight));
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() + moveIncrement),recheight));
	}
	
	public void moveUp()
	{
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() - moveIncrement),recheight));
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),toprecs.get(NUMRECS - 1).getImage().getY() - moveIncrement),recheight));
	}
	
	//returns a random valid height for the new middle rectangle
	public int randomMidHeight()
	{
		int max = 10000;
		int min = 0;
		
		for(int x = 0; x < NUMRECS; x++)
		{
			if(toprecs.get(x).getImage().getY() > min)
				min = (int)toprecs.get(x).getImage().getY();
			if(bottomrecs.get(x).getImage().getY() < max)
				max = (int)bottomrecs.get(x).getImage().getY();
		}
		min += recheight + 10;
		max -= (recheight + min) + 10;
		return min + (int)(Math.random() * max);
	}
	
	//moves the randomly generated middle rectangles
	public void updateMiddle()
	{
		if(middlerecs.get(0).getImage().getX() > -1 * RECWIDTH)
		{
			middlerecs.set(0,new Rec(new MovingImage("Images\\rec2.JPG",middlerecs.get(0).getImage().getX() - (RECWIDTH/5), middlerecs.get(0).getImage().getY()),73));
			middlerecs.set(1,new Rec(new MovingImage("Images\\rec2.JPG",middlerecs.get(1).getImage().getX() - (RECWIDTH/5), middlerecs.get(1).getImage().getY()),73));
		}
		else
		{
			middlerecs.set(0,new Rec(new MovingImage("Images\\rec2.JPG",middlerecs.get(1).getImage().getX() - (RECWIDTH/5), middlerecs.get(1).getImage().getY()),73));
			middlerecs.set(1,new Rec(new MovingImage("Images\\rec2.JPG",middlerecs.get(0).getImage().getX() + 580,randomMidHeight()),73));
		}
	}
	
	//checks to see if the helicopter is hit, returns true if it is
	public boolean isHit()
	{
		for(int y = 7; y <= 11; y++)
				if(isInBottomRange(y) || isInTopRange(y))
					return true;
		for(int z = 0; z <= 1; z++)
			if(isInMidRange(z))
				return true;
		return false;
	}
	
	//checks the helicopter against the middle recs
	public boolean isInMidRange(int num)
	{
		Rectangle middlecheck = new Rectangle((int)middlerecs.get(num).getImage().getX(),(int)middlerecs.get(num).getImage().getY(),RECWIDTH,73);
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY(),106,48);
		return middlecheck.intersects(coptercheck);
	}
	
	//checks the helicopter against the bottom recs
	public boolean isInBottomRange(int num)
	{
		Rectangle reccheck = new Rectangle((int)bottomrecs.get(num).getImage().getX(),(int)bottomrecs.get(num).getImage().getY(),RECWIDTH,bottomrecs.get(num).getHeight());
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY(),106,48);
		return reccheck.intersects(coptercheck);
	}
	
	//checks the helicopter against the top recs
	public boolean isInTopRange(int num)
	{
		int test = 90;
		if(!goingUp)
			test = 96;
		Rectangle reccheck = new Rectangle((int)toprecs.get(num).getImage().getX(),(int)toprecs.get(num).getImage().getY(),RECWIDTH,toprecs.get(num).getHeight());
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY() + 5,test,48);
		return reccheck.intersects(coptercheck);
	}
	
	//crashes the helicopter
	public void crash()
	{
		crashed = true;
		if(distance > maxDistance) //save the distance if it's a new high score
			maxDistance = distance;
		helicopter.setImage("Images\\crashcopter.gif");
		finishSmoke(); //finish the smoke animation and pause a few seconds
		initiate(); //restart the game
	}
	
	//moves the helicopter
	public void updateCopter()
	{
		upCount += .08;
		if(goingUp)
		{
			if(upCount < 3.5)
				helicopter.setPosition(XPOS,(double)(helicopter.getY() - (.3 + upCount)));
			else
				helicopter.setPosition(XPOS,(double)(helicopter.getY() - (1.2 + upCount)));
			helicopter.setImage("Images\\upCopter.GIF");	
		}
		else
		{
			if(upCount < 1)
				helicopter.setPosition(XPOS,(double)(helicopter.getY() + upCount));
			else
				helicopter.setPosition(XPOS,(double)(helicopter.getY() + (1.2 + upCount)));
			helicopter.setImage("Images\\helicopter.GIF");
		}
		if(isHit())
			crash();
	}
	
	/*
	 *MOUSE ACTION METHODS
	 */
	
	//Called when the mouse exits the game window
	public void mouseExited(MouseEvent e)
	{
		if(started)
			paused = true;
	}
	
	//Called when the mouse enters the game window
	public void mouseEntered(MouseEvent e)
	{
		//no use for the method but it must be here to use the MouseListener interface 
	}
	
	//Called when the mouse is released
	public void mouseReleased(MouseEvent e)
	{
		goingUp = false;
		upCount = 0;
		if(paused)
			paused = false;
	}
	
	//Called when the mouse is pressed
	public void mousePressed(MouseEvent e)
	{
		if (!started)
			started = true;
		goingUp = true;
		upCount = 0;
	}
	
	//Called when the mouse is released
	public void mouseClicked(MouseEvent e)
	{
		//no use for the method but it must be here to use the MouseListener interface 
	}
}



So..I know that was a ton of code, but I really don't understand what I'm setting up incorrectly. I take the class file HelicopterForm.class and then I get a bunch of errors like "Exception: java.lang.NoClassDefFoundError: ImagePanel"
I'm guessing I'm just making a really small error somewhere, but could somebody please help me out? I know it's a lot of code, but I'd really like to put this online. If there's a better way of doing this let me know, otherwise what am I doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Can't get an Applet working

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Can't get an Applet working

Posted 10 June 2009 - 04:54 PM

I presume you dont have all your classes straight underneath each other like that, but in their own classes? You might try making them public classes, but I'm not sure what the default is. Can you show your stack trace?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 05:01 PM

Not really need to post your code
The problem is not there if it works from JCreator
How do you Jar it
How do you copy it to the Web
What does your .html file (the part that load the Applet) looks like ?
Was This Post Helpful? 0
  • +
  • -

#4 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Re: Can't get an Applet working

Posted 10 June 2009 - 05:09 PM

View Postnick2price, on 10 Jun, 2009 - 03:54 PM, said:

I presume you dont have all your classes straight underneath each other like that, but in their own classes? You might try making them public classes, but I'm not sure what the default is. Can you show your stack trace?
No, they were originally all in their own classes but I wasn't sure how to have multiple classes in an applet so I dumped them into one. I had to make it so they weren't public (except HelicopterForm) after doing that.
Stack Trace from the Java Console that comes up after clicking on the error message:
java.lang.NoClassDefFoundError: ImagePanel
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: ImagePanel
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	... 8 more
Caused by: java.io.IOException: Stream closed.
	at java.net.PlainSocketImpl.available(Unknown Source)
	at java.net.SocketInputStream.available(Unknown Source)
	at java.io.BufferedInputStream.available(Unknown Source)
	at sun.net.www.http.ChunkedInputStream.readAheadNonBlocking(Unknown Source)
	at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source)
	at sun.net.www.http.ChunkedInputStream.available(Unknown Source)
	at sun.net.www.MeteredStream.available(Unknown Source)
	at java.io.BufferedInputStream.read(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 12 more
Exception: java.lang.NoClassDefFoundError: ImagePanel


View Postpbl, on 10 Jun, 2009 - 04:01 PM, said:

Not really need to post your code
The problem is not there if it works from JCreator
How do you Jar it
How do you copy it to the Web
What does your .html file (the part that load the Applet) looks like ?

- Figured it might help :blush:
- In the command prompt..but that's not related to the applet, is it?
- By uploading the .class file and all the images associated with the code
- <APPLET CODE="HelicopterForm.class" WIDTH=818 HEIGHT=568></APPLET>
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 05:40 PM

View Posttv3636, on 10 Jun, 2009 - 04:09 PM, said:

- In the command prompt..but that's not related to the applet, is it?
- By uploading the .class file and all the images associated with the code
- <APPLET CODE="HelicopterForm.class" WIDTH=818 HEIGHT=568></APPLET>

show us the output of the DIR (ls on Unix) of the directory where all that stuff is on the web
Was This Post Helpful? 0
  • +
  • -

#6 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Can't get an Applet working

Posted 10 June 2009 - 05:40 PM

If Helicopter class is your applet class, why is it place in the middle of the code? Cant check at the moment, in the middle of some big poker tournies, but having ImagePanel class placed above your helicopter class might cause it to not be picked up, which is why you might be getting the class not found error when you compile. Try placing your applet class at the top, or even better, seperate the classes or place them into a package.

@pbl. His getting a compile time error, so wouldnt this suggest an error with the code rather than location?

This post has been edited by nick2price: 10 June 2009 - 05:42 PM

Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 05:57 PM

View Postnick2price, on 10 Jun, 2009 - 04:40 PM, said:

@pbl. His getting a compile time error, so wouldnt this suggest an error with the code rather than location?

Heven't seen any compile error posted but just run time error "class not found exception"
Sure if there are compile error no need to ftp the stuff to a web site
Was This Post Helpful? 0
  • +
  • -

#8 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Re: Can't get an Applet working

Posted 10 June 2009 - 06:01 PM

http://tv3636.webs.com/index.htm Not sure what "output of the DIR" means, but there's the page...hopefully that helps.

And I originally had HelicopterForm on top but thought maybe ImagePanel wasn't being reached for some reason because it was below, so I switched and it didn't change anything.

I guess I should look into packaging, I don't know how to do that but it seems like that would be the easiest option.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 07:27 PM

oups.... you just can't do that

		imageName = "Images\\rec2.JPG";
			   
		helicopter = new MovingImage("Images\\helicopter.GIF",XPOS,270);



Applets are running on the browser of the PC that download them from the net but cannot access the local file system they can only access the system file of the host they are coming from

Applets have 2 methods getCodeBase() and getDocumentBase() that return the URL from where they are coming
then you can append yiour :Images\\filename.gif or .jpg to it




was a good idea to post your code after all :D
Was This Post Helpful? 0
  • +
  • -

#10 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Re: Can't get an Applet working

Posted 10 June 2009 - 07:53 PM

Well, thank you for pointing that out, but I'm still getting the same error with ImagePanel..I really don't know what to do about it :\
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 08:02 PM

View Posttv3636, on 10 Jun, 2009 - 06:53 PM, said:

Well, thank you for pointing that out, but I'm still getting the same error with ImagePanel..I really don't know what to do about it :\

I said post a DIR or ls of your directory on the host...
I want to see what files you have there
if its a .jar the content of the .jar

Without that it is the blind leading the blind
And repost the code where you call getCodeBase()
Was This Post Helpful? 0
  • +
  • -

#12 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Re: Can't get an Applet working

Posted 10 June 2009 - 08:17 PM

Posted Image
Files are at http://tv3636.webs.com/Images/back.JPG and so on
Still not sure what you mean..but I think that's it.

I don't think it's an issue with missing images..because the code runs even if the images aren't there, it just looks like a gray background. Here is the updated code though:

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

class MovingImage
{
	private Image image;		//The picture
	private double x;			//X position
	private double y;			//Y position
	
	//Construct a new Moving Image with image, x position, and y position given
	public MovingImage(Image img, double xPos, double yPos)
	{
		image = img;
		x = xPos;
		y = yPos;
	}
	
	//Construct a new Moving Image with image (from file path), x position, and y position given
	public MovingImage(String path, double xPos, double yPos)
	{
		this(new ImageIcon(path).getImage(), xPos, yPos);	
	}
	
	public void setPosition(double xPos, double yPos)
	{
		x = xPos;
		y = yPos;
	}
	
	public void setImage(String path)
	{
		image = new ImageIcon(path).getImage();
	}
	
	public void setY(double newY)
	{
		y = newY;
	}
	
	public void setX(double newX)
	{
		x = newX;
	}
	
	public double getX()
	{
		return x;
	}
	
	public double getY()
	{
		return y;
	}
	
	public Image getImage()
	{
		return image;
	}
}

class Rec
{
	private MovingImage image;
	private int height;
	public Rec(MovingImage i, int newHeight)
	{
		image = i;
		height = newHeight;
	}
	
	public MovingImage getImage()
	{
		return image;
	}
	
	public int getHeight()
	{
		return height;
	}
}

class ImagePanel extends JPanel {

	  private Image background; //The background image
	  private ArrayList<Rec> top;	//An array list of foreground images
	private ArrayList<Rec> bottom;
	private ArrayList<Rec> middle;
	private MovingImage copter;
	private ArrayList<MovingImage> smoke;
	
	//Constructs a new ImagePanel with the background image specified by the file path given
	  public ImagePanel(String img) 
	  {
		  this(new ImageIcon(img).getImage());
	  }

	//Constructs a new ImagePanel with the background image given
	  public ImagePanel(Image img)
	  {
		background = img;
		Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		
		top = new ArrayList<Rec>();
		middle = new ArrayList<Rec>();
		bottom = new ArrayList<Rec>();
		
		smoke = new ArrayList<MovingImage>();
	  }

	//called through repaint()
	  public void paintComponent(Graphics g) 
	  {
		  //Paint the background
		g.drawImage(background, 0, 0, null); 
		//Paint all other images on top of it
		for(Rec img : top)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(Rec img : middle)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(Rec img : bottom)
			g.drawImage(img.getImage().getImage(), (int)(img.getImage().getX()), (int)(img.getImage().getY()), null);
		for(MovingImage img : smoke)
			g.drawImage(img.getImage(), (int)(img.getX()), (int)(img.getY()), null);
		if(copter != null)
			g.drawImage(copter.getImage(), (int)(copter.getX()), (int)(copter.getY()), null);
		drawStrings(g);
	  }
 	
 	//draws various strings on the screen
 	public void drawStrings(Graphics g)
 	{
 		g.setFont(new Font("Arial",Font.BOLD,20));
		g.drawString("Distance: " + HelicopterForm.distance,30,500);
		g.setFont(new Font("Arial",Font.BOLD,20));
		if (HelicopterForm.distance > HelicopterForm.maxDistance)
			g.drawString("Best: " + HelicopterForm.distance,650,500);
		else
			g.drawString("Best: " + HelicopterForm.maxDistance,650,500);
		if(HelicopterForm.paused && !HelicopterForm.crashed)
		{
				g.setColor(Color.WHITE);
				g.setFont(new Font("Chiller",Font.BOLD,72));
				g.drawString("Paused",325,290);
				g.setFont(new Font("Chiller",Font.BOLD,30));
				g.drawString("Click to unpause.",320,340);
		}
		if(!HelicopterForm.started)
		{
			g.setColor(Color.WHITE);
			g.setFont(new Font("Chiller",Font.BOLD,72));
			g.drawString("Helicopter Game",205,220);
			g.setFont(new Font("Chiller",Font.BOLD,50));
			g.drawString("Click to Start",320,310);
		}
 	}
 	
	  //Calls paintComponent with updated images
	  public void updateImages(ArrayList<Rec> newTop,ArrayList<Rec> newMiddle,ArrayList<Rec> newBottom,MovingImage newCopter,ArrayList<MovingImage> newSmoke)
	  {
		  top = newTop;
		  copter = newCopter;
		  middle = newMiddle;
		  bottom = newBottom;
		  smoke = newSmoke;
		  repaint();	//Repaints the frame
	  }
}



public class HelicopterForm extends Applet implements MouseListener
{
	private JFrame background;
	private ImagePanel back;
	
	public static boolean paused;
	public static boolean crashed;
	public static boolean started;
	public static boolean playedOnce;	
	
	public boolean goingUp;
	private double upCount;
	
	public static int distance;
	public static int maxDistance;
	
	public final int XPOS;
	public final int NUMRECS;
	public final int RECWIDTH;
	
	public int recheight;
	public String imageName;
	
	private int moveIncrement;
	private int numSmoke;
	
	private ArrayList<Rec> toprecs;
	private ArrayList<Rec> bottomrecs;
	private ArrayList<Rec> middlerecs;
	private ArrayList<MovingImage> smoke;
	private MovingImage helicopter;
	
	/*Graphics information:
	 *Background is 812 x 537
	 *Floor is 74 and Ceiling is 72 pixels high
	 *28 rectangles across that are 29 x 73
	 */
	
	public HelicopterForm()
	{
		NUMRECS = 28; //Number of bottom/top recs
		RECWIDTH = 29; //Width of all recs
		XPOS = 200; //X position of helicopter
		playedOnce = false; //checks for the first playthrough
		maxDistance = 0; //Sets the high score to 0
		
		initiate(); //Initiates the game
	}
	
	public void initiate()
	{
		if(!playedOnce) //if first play through
		{
			background = new JFrame("Helicopter Game"); 
			background.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //closes the program when the window is closed
			background.setResizable(false); //don't allow the user to resize the window
			background.setSize(new Dimension(818,568));
			background.setVisible(true);
			
			back = new ImagePanel(getCodeBase() + "Images/back.JPG");
			background.add(back); //puts the background image in the background of the frame
			back.addMouseListener(this);
			
			playedOnce = true;
		}
		//initialize various booleans
		goingUp = false; //helicopter going up or down
		paused = false; //game paused or not
		crashed = false; //helicopter crashed or not
		started = false; //game started or not
		
		distance = 0;
		upCount = 0;
		
		recheight = 73; //initial rec height
		imageName = getCodeBase() + "Images/rec2.JPG";
		
		moveIncrement = 2;
		numSmoke = 15; //number of smoke bubbles
		
		toprecs = new ArrayList<Rec>();
		middlerecs = new ArrayList<Rec>();
		bottomrecs = new ArrayList<Rec>();
		smoke = new ArrayList<MovingImage>();
		
		helicopter = new MovingImage(getCodeBase() + "Images/helicopter.GIF",XPOS,270);
		
		//initialize the rectangle arrays
		for(int x = 0; x < NUMRECS; x++)
			toprecs.add(new Rec(new MovingImage(imageName,RECWIDTH*x,30),recheight));
		for(int x = 0; x < NUMRECS; x++)
			bottomrecs.add(new Rec(new MovingImage(imageName,RECWIDTH*x,450),recheight));
			
		middlerecs.add(new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",1392,randomMidHeight()),73));
		middlerecs.add(new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",1972,randomMidHeight()),73));
	
		drawRectangles();
	}
	
	public void drawRectangles()
	{
		long last = System.currentTimeMillis();
		long lastCopter = System.currentTimeMillis();
		long lastSmoke = System.currentTimeMillis();
		double lastDistance = (double)System.currentTimeMillis();
		
		int firstUpdates = 0;
		
		while(true)
		{
			//score increased by time rather than rectangles passed
			if(!paused && !crashed && started && (double)System.currentTimeMillis() - (double)(2900/40) > lastDistance)
			{	
				lastDistance = System.currentTimeMillis();
				distance++;
			}	
			
			//middle rectangles and helicopter updated every 10 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 10 > lastCopter)
			{
				lastCopter = System.currentTimeMillis();
				updateCopter();
				updateMiddle();
			}
			
			//top and bottom rectangles updated every 100 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 100 > last)
			{
				last = System.currentTimeMillis();
				updateRecs();
			}
			
			//smoke behind helicopter updated every 75 milliseconds
			if(!paused && !crashed && started && System.currentTimeMillis() - 75 > lastSmoke)
			{
				lastSmoke = System.currentTimeMillis();
				if (firstUpdates < numSmoke)
				{
					firstUpdates++;
					smoke.add(new MovingImage(getCodeBase() + "Images/smoke.GIF",187,helicopter.getY()));
					for(int x = 0; x < firstUpdates; x++)
						smoke.set(x,new MovingImage(getCodeBase() + "Images/smoke.GIF",smoke.get(x).getX() - 12, smoke.get(x).getY()));
				}
				else
				{
					for(int x = 0; x < numSmoke - 1; x++)
						smoke.get(x).setY(smoke.get(x+1).getY());
					smoke.set(numSmoke - 1,new MovingImage(getCodeBase() + "Images/smoke.GIF",187,helicopter.getY()));
				}
					}
					back.updateImages(toprecs,middlerecs,bottomrecs,helicopter,smoke);
				}
	}
	
	//finishes the smoke animation after a crash
	public void finishSmoke()
	{
		long lastSmoke = System.currentTimeMillis();
		long lastSmoke2 = lastSmoke;
		while(System.currentTimeMillis() - 3000 < lastSmoke2)
		{
			if(System.currentTimeMillis() - 75 > lastSmoke)
			{
				lastSmoke = System.currentTimeMillis();
				for(int x = 0; x < smoke.size(); x++)
						smoke.get(x).setX(smoke.get(x).getX() - 12);
			}
			back.updateImages(toprecs,middlerecs,bottomrecs,helicopter,smoke);
		}
	}
	
	//updates the top and bottom rectangles' positions
	public void updateRecs()
	{
		for(int x = 0; x < (NUMRECS - 1); x++) //move all but the last rectangle 1 spot to the left
		{
			toprecs.set(x,new Rec(new MovingImage(toprecs.get(x+1).getImage().getImage(),RECWIDTH*x,toprecs.get(x+1).getImage().getY()),recheight));
			bottomrecs.set(x,new Rec(new MovingImage(bottomrecs.get(x+1).getImage().getImage(),RECWIDTH*x,bottomrecs.get(x+1).getImage().getY()),recheight));
		}
		lastRec();
	}
	
	//places the last rectangle in the array with a lot of randomization
	public void lastRec()
	{
		if(distance % 400 == 0)
			moveIncrement++;
		if(distance % 500 == 0 && recheight != 153)
		{
			recheight += 20; //makes the game more difficult
			if(recheight == 93)
				imageName = getCodeBase() + "Images/rec3.JPG";
			else if(recheight == 113)
				imageName = getCodeBase() + "Images/rec4.JPG";
			else if(recheight == 133)
				imageName = getCodeBase() + "Images/rec5.JPG";
			else
				imageName = getCodeBase() + "Images/rec6.JPG";
		}
		if(toprecs.get(NUMRECS - 1).getImage().getY() < 2) //if too high, move down
			moveDown();
		else if (bottomrecs.get(NUMRECS - 1).getImage().getY() > 463) //else if too low, move up
			moveUp();
		else //else move randomly
		{
			if((int)(Math.random() * 30) == 20)
				randomMove();
			else
			{
				if((int)(Math.random() * 2) == 1)
					moveUp();
				else
					moveDown();
			}
		}
	}
	
	//3 movement methods for the last rectangle
	public void randomMove()
	{
		if(Math.random() < .5)
		{
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS-1),toprecs.get(NUMRECS - 1).getImage().getY() + (463 - bottomrecs.get(NUMRECS - 1).getImage().getY())),recheight));
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),463),recheight));
		}
		else
		{
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() - (0 + toprecs.get(NUMRECS - 1).getImage().getY())),recheight));
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS-1),0),recheight));
		}
	}
	
	public void moveDown()
	{
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),toprecs.get(NUMRECS - 1).getImage().getY() + moveIncrement),recheight));
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() + moveIncrement),recheight));
	}
	
	public void moveUp()
	{
			bottomrecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),bottomrecs.get(NUMRECS - 1).getImage().getY() - moveIncrement),recheight));
			toprecs.set((NUMRECS - 1),new Rec(new MovingImage(imageName,RECWIDTH*(NUMRECS - 1),toprecs.get(NUMRECS - 1).getImage().getY() - moveIncrement),recheight));
	}
	
	//returns a random valid height for the new middle rectangle
	public int randomMidHeight()
	{
		int max = 10000;
		int min = 0;
		
		for(int x = 0; x < NUMRECS; x++)
		{
			if(toprecs.get(x).getImage().getY() > min)
				min = (int)toprecs.get(x).getImage().getY();
			if(bottomrecs.get(x).getImage().getY() < max)
				max = (int)bottomrecs.get(x).getImage().getY();
		}
		min += recheight + 10;
		max -= (recheight + min) + 10;
		return min + (int)(Math.random() * max);
	}
	
	//moves the randomly generated middle rectangles
	public void updateMiddle()
	{
		if(middlerecs.get(0).getImage().getX() > -1 * RECWIDTH)
		{
			middlerecs.set(0,new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",middlerecs.get(0).getImage().getX() - (RECWIDTH/5), middlerecs.get(0).getImage().getY()),73));
			middlerecs.set(1,new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",middlerecs.get(1).getImage().getX() - (RECWIDTH/5), middlerecs.get(1).getImage().getY()),73));
		}
		else
		{
			middlerecs.set(0,new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",middlerecs.get(1).getImage().getX() - (RECWIDTH/5), middlerecs.get(1).getImage().getY()),73));
			middlerecs.set(1,new Rec(new MovingImage(getCodeBase() + "Images/rec2.JPG",middlerecs.get(0).getImage().getX() + 580,randomMidHeight()),73));
		}
	}
	
	//checks to see if the helicopter is hit, returns true if it is
	public boolean isHit()
	{
		for(int y = 7; y <= 11; y++)
				if(isInBottomRange(y) || isInTopRange(y))
					return true;
		for(int z = 0; z <= 1; z++)
			if(isInMidRange(z))
				return true;
		return false;
	}
	
	//checks the helicopter against the middle recs
	public boolean isInMidRange(int num)
	{
		Rectangle middlecheck = new Rectangle((int)middlerecs.get(num).getImage().getX(),(int)middlerecs.get(num).getImage().getY(),RECWIDTH,73);
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY(),106,48);
		return middlecheck.intersects(coptercheck);
	}
	
	//checks the helicopter against the bottom recs
	public boolean isInBottomRange(int num)
	{
		Rectangle reccheck = new Rectangle((int)bottomrecs.get(num).getImage().getX(),(int)bottomrecs.get(num).getImage().getY(),RECWIDTH,bottomrecs.get(num).getHeight());
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY(),106,48);
		return reccheck.intersects(coptercheck);
	}
	
	//checks the helicopter against the top recs
	public boolean isInTopRange(int num)
	{
		int test = 90;
		if(!goingUp)
			test = 96;
		Rectangle reccheck = new Rectangle((int)toprecs.get(num).getImage().getX(),(int)toprecs.get(num).getImage().getY(),RECWIDTH,toprecs.get(num).getHeight());
		Rectangle coptercheck = new Rectangle((int)helicopter.getX(),(int)helicopter.getY() + 5,test,48);
		return reccheck.intersects(coptercheck);
	}
	
	//crashes the helicopter
	public void crash()
	{
		crashed = true;
		if(distance > maxDistance) //save the distance if it's a new high score
			maxDistance = distance;
		helicopter.setImage(getCodeBase() + "Images/crashcopter.gif");
		finishSmoke(); //finish the smoke animation and pause a few seconds
		initiate(); //restart the game
	}
	
	//moves the helicopter
	public void updateCopter()
	{
		upCount += .08;
		if(goingUp)
		{
			if(upCount < 3.5)
				helicopter.setPosition(XPOS,(double)(helicopter.getY() - (.3 + upCount)));
			else
				helicopter.setPosition(XPOS,(double)(helicopter.getY() - (1.2 + upCount)));
			helicopter.setImage(getCodeBase() + "Images/upCopter.GIF");	
		}
		else
		{
			if(upCount < 1)
				helicopter.setPosition(XPOS,(double)(helicopter.getY() + upCount));
			else
				helicopter.setPosition(XPOS,(double)(helicopter.getY() + (1.2 + upCount)));
			helicopter.setImage(getCodeBase() + "Images/helicopter.GIF");
		}
		if(isHit())
			crash();
	}
	
	/*
	 *MOUSE ACTION METHODS
	 */
	
	//Called when the mouse exits the game window
	public void mouseExited(MouseEvent e)
	{
		if(started)
			paused = true;
	}
	
	//Called when the mouse enters the game window
	public void mouseEntered(MouseEvent e)
	{
		//no use for the method but it must be here to use the MouseListener interface 
	}
	
	//Called when the mouse is released
	public void mouseReleased(MouseEvent e)
	{
		goingUp = false;
		upCount = 0;
		if(paused)
			paused = false;
	}
	
	//Called when the mouse is pressed
	public void mousePressed(MouseEvent e)
	{
		if (!started)
			started = true;
		goingUp = true;
		upCount = 0;
	}
	
	//Called when the mouse is released
	public void mouseClicked(MouseEvent e)
	{
		//no use for the method but it must be here to use the MouseListener interface 
	}
}


Not using any jar files for this..

This post has been edited by tv3636: 10 June 2009 - 08:17 PM

Was This Post Helpful? 0
  • +
  • -

#13 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Can't get an Applet working

Posted 10 June 2009 - 08:22 PM

What files do you have in your root directory, dir tv3636
Was This Post Helpful? 0
  • +
  • -

#14 tv3636  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-February 09

Re: Can't get an Applet working

Posted 10 June 2009 - 08:25 PM

HelicopterForm.java and HelicopterForm.class

By the way, I get the following error in JCreator now:

Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:152)
at HelicopterForm.initiate(HelicopterForm.java:242)
at HelicopterForm.<init>(HelicopterForm.java:229)
at HelicopterDriver.main(HelicopterForm.java:15)

Process completed.


EDIT: I think JCreator is using other files that I removed from the project..let me make a new one.

This post has been edited by tv3636: 10 June 2009 - 08:27 PM

Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Can't get an Applet working

Posted 10 June 2009 - 08:29 PM

Not an Applet specialist but wonder if
  back = new ImagePanel(getCodeBase() + "Images/back.JPG");


shouldn't be
  back = new ImagePanel(getCodeBase() + "/Images/back.JPG");


getCodeBase() is an absolute path
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3