Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 10-25-2005, 02:28 PM   #1 (permalink)
see-seA
Registered User
 
Join Date: Oct 2005
Posts: 2
see-seA is on a distinguished road
JApplet giving me grief - plz assist

I am busy working on an Applet that is meant to work on the web. The thing is that if I run the code as is, it works on my computer when run locally, however it refuses to work when I upload the class files to a webserver and try run the applet through a browser (on my comp I use AppletViewer).

Please could someone do me a HUGE favour and take a look at the [simplified] code below and let me know what I've been doing wrong.

Much appreciated.

Frogger.java
Code:
// <applet code="Frogger.class" width="465" height="400"></applet> import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Frogger extends JApplet { private ArrayList<Car> cars; private Frog frog; private ImageIcon tree; public void init() { // places cars into arraylist on init cars = new ArrayList<Car>(); Car car; for( int i = 0; i < 12; i++ ) { if( i <= 3 || i >= 8 ) { car = new Car(2); cars.add( car ); } else if( i >= 4 && i <= 7 ) { car = new Car(1); cars.add( car ); } } // setup the frog frog = new Frog(); // setup trees tree = new ImageIcon( "images/tree.gif" ); } public void paint( Graphics page ) { setBackground( new Color(21,205,56) ); // trees tree.paintIcon( this, page, 20, 10 ); tree.paintIcon( this, page, 320, 10 ); tree.paintIcon( this, page, 70, 330 ); tree.paintIcon( this, page, 270, 330 ); // frog frog.getIcon().paintIcon( this, page, 50, 50 ); // cars cars.get(2).getIcon().paintIcon( this, page, 100, 100 ); cars.get(7).getIcon().paintIcon( this, page, 200, 200 ); } }
Car.java
Code:
import javax.swing.*; import java.util.*; import java.awt.*; public class Car { private ImageIcon carPic; private int direction; public Car( int way ) { Random generator = new Random(); int type = generator.nextInt( 4 ) + 1; direction = way; if( type == 1 && direction == 1 ) carPic = new ImageIcon( "images/car1left.gif" ); else if( type == 1 && direction == 2 ) carPic = new ImageIcon( "images/car1right.gif" ); else if( type == 2 && direction == 1 ) carPic = new ImageIcon( "images/car2left.gif" ); else if( type == 2 && direction == 2 ) carPic = new ImageIcon( "images/car2right.gif" ); else if( type == 3 && direction == 1 ) carPic = new ImageIcon( "images/car3left.gif" ); else if( type == 3 && direction == 2 ) carPic = new ImageIcon( "images/car3right.gif" ); else if( type == 4 && direction == 1 ) carPic = new ImageIcon( "images/car4left.gif" ); else if( type == 4 && direction == 2 ) carPic = new ImageIcon( "images/car4right.gif" ); } public ImageIcon getIcon() { return carPic; } }
Frog.java
Code:
import javax.swing.*; import java.awt.event.*; public class Frog extends JApplet { private ImageIcon frogPic; public Frog() { frogPic = new ImageIcon( "images/frog.gif" ); } public ImageIcon getIcon() { return frogPic; } }

Thanks so much.
__________________
see-seA is offline   Reply With Quote
Old 10-26-2005, 02:18 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
If I had to guess, it (for some reason) didn't like the "images/<whatever>.gif". But you should be getting some sort of exception. Are you getting eny sort of error message?
__________________
GitS
Belisarius is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:18 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle