| | |
Very Simple Applet Problem
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 79
Reputation:
Solved Threads: 1
Ok, well I am JUST beginning to learn Java, and I have run into a little stumbling block. I am attempting to write a little applet, but it doesn't seem to want to run.
My Java code:
My HTML:
So...I'm not quite sure where I am going wrong. I receive no errors while compiling and there isn't much code for me to mess up.
Could anybody help me with this problem?
Thanks in advance.
My Java code:
java Syntax (Toggle Plain Text)
import java.awt.*; import java.applet.*; public class TestApplet extends Applet { public void paint(Graphics g) { g.drawString("Please work my little applet!", 20, 30); } }
My HTML:
html Syntax (Toggle Plain Text)
<HTML> <HEAD><TITLE>Test Applet</TITLE></HEAD> <BODY> <applet code="TestApplet.class" width="300" height ="300"> </BODY> </HTML>
So...I'm not quite sure where I am going wrong. I receive no errors while compiling and there isn't much code for me to mess up.
Could anybody help me with this problem?
Thanks in advance.
0
#2 Oct 10th, 2009
Read the Java tutorial on applets, here. You are missing a key method every applet needs.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
•
•
Join Date: Sep 2008
Posts: 79
Reputation:
Solved Threads: 1
0
#3 Oct 10th, 2009
Thanks for the link, except that example is not even working. I copied and pasted the code verbatim and I still get a little gray box of nothing.
Thanks again.
EDIT: Well, this is odd. I am able to view my applet within an IDE but not through a browser (Firefox 3.5). Any ideas to why this is?
Thanks again.
EDIT: Well, this is odd. I am able to view my applet within an IDE but not through a browser (Firefox 3.5). Any ideas to why this is?
Last edited by SoulMazer; Oct 10th, 2009 at 8:56 pm.
0
#4 Oct 11th, 2009
Not really lol. I never had to integrate them with webpages, I just had to make some for a class once. I'm sure someone else around here will know.
Last edited by jasimp; Oct 11th, 2009 at 12:57 am.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
2
#5 Oct 11th, 2009
There are a couple of things you can check for this problem:
1. Is your browser set to "Enable Java" ? (Go to Tools > Options > Content Panel
2. Ensure that your applet file (class file) have the appropriate file-access permission and the browser should be able to read it (read/write access to files)
3. Read on security policies that go with your applets when deploying it to a browser.
2. Lastly, Did you get any error messages inside the browser?
hope that helps
1. Is your browser set to "Enable Java" ? (Go to Tools > Options > Content Panel
2. Ensure that your applet file (class file) have the appropriate file-access permission and the browser should be able to read it (read/write access to files)
3. Read on security policies that go with your applets when deploying it to a browser.
2. Lastly, Did you get any error messages inside the browser?
hope that helps
•
•
Join Date: Sep 2008
Posts: 79
Reputation:
Solved Threads: 1
0
#6 Oct 11th, 2009
1. Yes, Java is enabled.
2. Both of the files have read/write/execute access.
3. Sorry, could you explain this a little bit?
4. No, I received no error messages in Linux or Windows.
If you would like to see this for yourself, (in no way am I advertising my website) you can see it here: http://patbriggs.net/mytest.html
Thanks for the ideas.
2. Both of the files have read/write/execute access.
3. Sorry, could you explain this a little bit?
4. No, I received no error messages in Linux or Windows.
If you would like to see this for yourself, (in no way am I advertising my website) you can see it here: http://patbriggs.net/mytest.html
Thanks for the ideas.
•
•
Join Date: Aug 2008
Posts: 203
Reputation:
Solved Threads: 13
0
#7 Oct 12th, 2009
Hello! Most Applets now extend the JApplet class now. (JApplet is part of the javax.swing package) So you should probably be extending that instead. also, all applets make a call to init(), start(), destroy(), and stop(). The paint() method is located in the Container class. anyways, that's just some background info for applets. You should add in the above methods to your code, because they're called by the browser to start the applet. hope this helps =)
0
#8 Oct 12th, 2009
Actually, when I opened your link there was an error message displayed in the java console. If you are using Mozilla you can go to Tools > Java Console. If you are using Internet Explorer , right click on the applet area and select Java Console.
The error was a 'java.lang.NoClassDefFoundError' which is caused when your browser couldn't locate the *.class file of your applet. There are two options you can go about solving this:
1. make sure all your *.class files are in the same directory as to your html file; or
2. use CODEBASE attribute of the APPLET tag in your html file(point the codebase to the directory of where your *.class files of the applet are located)
About the security thing read it here:
http://java.sun.com/developer/online...ok/signed.html
hope that helps
The error was a 'java.lang.NoClassDefFoundError' which is caused when your browser couldn't locate the *.class file of your applet. There are two options you can go about solving this:
1. make sure all your *.class files are in the same directory as to your html file; or
2. use CODEBASE attribute of the APPLET tag in your html file(point the codebase to the directory of where your *.class files of the applet are located)
About the security thing read it here:
http://java.sun.com/developer/online...ok/signed.html
hope that helps
Last edited by Jocamps; Oct 12th, 2009 at 1:01 am.
•
•
Join Date: Sep 2008
Posts: 79
Reputation:
Solved Threads: 1
0
#9 Oct 12th, 2009
Ok, well it's rather hard for me to test as whenever I visit the page with my applet on it, my browser crashes (so all I know is that it doesn't work).
And both my .class file and my .html file are already in the same directory. I have also added a "codebase" element to my applet tag.
Updated code:
Thanks for all the great help. But have any more ideas?
And both my .class file and my .html file are already in the same directory. I have also added a "codebase" element to my applet tag.
Updated code:
html Syntax (Toggle Plain Text)
<HTML> <HEAD> <TITLE>Test Applet</TITLE> </HEAD> <BODY> <applet codebase="/" code="TestApplet.class" width="300" height ="300"> </applet> </BODY> </HTML>
Thanks for all the great help. But have any more ideas?
Last edited by SoulMazer; Oct 12th, 2009 at 1:18 am.
•
•
Join Date: Sep 2008
Posts: 79
Reputation:
Solved Threads: 1
0
#10 30 Days Ago
Okay, I would like to start by say I'm sorry if this forum has a strict "no-bump after x days" etiquette, but I found a solution to my problem and I thought I would share. Although I did successfully have the latest JRE installed, I guess I didn't have a Java plugin installed for my browser. Being on Linux, I have no idea why my package manager would install only the JRE and not the browser plugin...oh well.
![]() |
Similar Threads
- Help with Simple Math Problem (Python)
- Applet Problem... (Java)
- Applet, thread (Java)
- Simple problem (Java)
- Trying to add a simple applet to a web page (Java)
- Custom CharsetProvider doesn't get loaded in signed applet (Java)
- DrawHouse Code Problem (Java)
Other Threads in the Java Forum
- Previous Thread: Rock, Paper, Scissor Game Help
- Next Thread: String value not found
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






