This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes First time with applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "First time with applets" Watch "First time with applets" New topic
Author

First time with applets

P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
I'm having a bit of trouble getting my applet to appear. I am using bravenet.com for my webhost and have uploaded the file using the file manager. My code for the applet is this



And my code for my website is this



When I open up the page it says "Error. Click for details"
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
The CODE attribute takes just the class name, which is "BallRoom" or "BallRoom.class". If the class files are not in the same directory as the HTML file, then you need to use a CODEBASE attribute to point to it; in this case it would have a value of "java". The AppletsFaq points to a tutorial on all the details of the APPLET tag.

As an aside, there's no point in calling setSize in an applet - it takes its size from the HEIGHT and WIDTH attributes of the applet tag, and can't be resized.

Lastly, whenever you have problems with applets, check for error messages in the Java Console - that's where any exceptions will be logged, and it's where any System.out messages written by code would show up.


Ping & DNS - my free Android networking tools app
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
I checked the java console and it didn't say anything other than the version of java I had. I figured out how to solve the problem by using the files URL.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
Do you mean an URL that starts with "file:///"? If so, that works on your local machine only - not on an actual host.
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
Here is my HTML code but it doesn't work. It is still somehow finding the files on my computer because when I open it up on any other computer it doesn't work.



I got the codebase idea from the java tutorials but it doesn't work. Any help?
If you type in
http://drenguin.bravehost.com/Applet.class
then it shows you the class.

P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
Also, the applet runs on my computer even when the file is not on the server so I know it is somehow getting it from the computer.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
If you type in
http://drenguin.bravehost.com/Applet.class
then it shows you the class.

Actually, I'm getting some kind of "page not found" message for that URL.
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
Sorry I removed the file for a little bit to see if the applet would run without the file, it should work now if you click on the link!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
It seems that should work; what exactly happens if you try it - is there an exception in the Java Console? Be sure to set Java 6 as the JRE, since that's what the applet is compiled for.
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
How does one set a JRE?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
Using the Java Plugin control panel on Windows, or using /Applications/Utilities/Java Preferences.app on OS X.
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
I used the Java Preferences thingy and it was already on 6.
I am assuming that you have Java 6 also so could you tell me if this site has an ok button, that is my applet. Pardon the ads but I'm using one of those free website things right now.

http://drenguin.bravehost.com/Applet.htm
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
Actually, I don't use Java 6. After setting Java 6 as the default JRE in the Java Preferences.app neither Safari nor Firefox are able to run any applets, so I'm not sure what's going on with yours.
P Mc Gartoll
Greenhorn

Joined: Jul 12, 2010
Posts: 19
The applet works on my computer. On other computers they now get the java loading sign (the cup with the arrows around it)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First time with applets
 
Similar Threads
Not to show the ellipse?
Bouncing balls
Not drawing the Button?
Adding a sound file to a java applet
Not able to change Background color of a component