Results 1 to 11 of 11
- 03-04-2011, 04:24 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
SOLVED: Embedding JApplet into webpage first time, nothing shows?
I've been working on a project locally and it's going great, and I figure it's time to start seeing how it runs on the web. The project will have a jar file with all the classes used, and the archive tag will point to my main GUI class. Still not sure if all that will work.
Anyway I got the jar file on the site and the html page coded, and a box the right size comes up but nothing is displayed. I figure I'd test it with the JApplet java uses when talking about applets in the beginning
my web code isJava Code:import javax.swing.JApplet; import javax.swing.SwingUtilities; import javax.swing.JLabel; public class HelloWorld extends JApplet { //Called when this applet is loaded into the browser. public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JLabel lbl = new JLabel("Hello World"); add(lbl); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } } }
Here is a link to what's going on. I know the size is huge but this shouldn't affect it from showing.Java Code:<html> <head> <title> favorites / bookmark title goes here </title> </head> <body bgcolor="black" text="white"> <APPLET CODE="HelloWorld.class" WIDTH=800 HEIGHT=789> </APPLET> </body> </html>
Any help is appreciated, this is exciting regardless!
UPDATE -- Just read here that they are using a JNLP file and the <script> tags to load this onto the page. Is this necessary? Advantageous?Last edited by enerj; 03-08-2011 at 11:00 PM. Reason: solution found
- 03-07-2011, 06:17 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
You are missing the inner class file
HelloWorld$1.class
Put that at the same directory.
It's a good idea to keep the Java Console on during development. The exception thrown says that "HelloWorld$1.class" is missing on the console.Last edited by cultclassic; 03-07-2011 at 06:21 PM.
- 03-07-2011, 08:00 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
Great tip about the Java console, I see this being valuable in the future.
I am still confused though, why is it looking for
HelloWorld$1.class
when in my html file I tell it to look for
<APPLET CODE="HelloWorld.class" WIDTH=800 HEIGHT=789>
- 03-07-2011, 08:10 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
Classes with $ in the name are "inner classes". The main class looks loads first, and it then loads/runs the inner class. In your case the statement "new Runnable()..." is creating a new class.
Google "inner class".
- 03-07-2011, 08:25 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
Ok I will read up on it, but even my JApplets without the "new Runnable()" call won't load. Classes that extend Applet work okay, but I haven't gotten a JApplet working yet.
Are there any differences between loading these two to the web? I will take out that runnable call and see if I can get it working, but I don't think I'll have much luck.
Thanks for the help
- 03-07-2011, 08:38 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
Actually your HelloWorld class works fine for me...
Last edited by cultclassic; 03-07-2011 at 11:40 PM.
- 03-07-2011, 11:05 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
I see you have the HelloWorld$1.class in your test folder, I just saw that in my bin folder for that project and I think it'll work if I add that. I just tested it with a simple JApplet using JPanels and it works, so thank you.
Now on to the real issue at hand. Using your console tip, I investigated why my main program that is contained in a jar file won't work. The error from the console is saying it can't find the class "SplineInterpolator" which is an Apache math commons package I've added to my project, and when I look in the jar file that my ARCHIVE tag points to, "commons-math-2.1.jar" is located in /lib and all the class files are in /.
This is the html call
and here is the error from the console.Java Code:<APPLET ARCHIVE="grapher.jar" CODE=GUImain.class WIDTH=800 HEIGHT=789> </APPLET>
Everything works great offline, it's the web transition I'm having trouble with. I know this is beyond the scope of this thread, but any additional help is much appreciated.Java Code:Exception in thread "thread applet-GUImain.class-6" java.lang.NoClassDefFoundError: org/apache/commons/math/analysis/interpolation/SplineInterpolator at Graph.<init>(Graph.java:42) at Graph.<init>(Graph.java:57) at GUIdefiner.<init>(GUIdefiner.java:90) at GUImain.init(GUImain.java:18) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
- 03-08-2011, 12:17 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
Include the location of commons-math-2.1.jar into your ARCHIVE or add it in the manifest file of grapher.jar
- 03-08-2011, 03:57 AM #9
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
Cult, thanks for single handedly teaching my java jar and applet basics =)
I've already started reading about manifest files and multiple JARs w/ ARCHIVE. If you've got time, what would a jar inside a jar call look like?
Java Code:<APPLET ARCHIVE="grapher.jar, grapher.jar/lib" CODE=GUImain.class WIDTH=800 HEIGHT=789> </APPLET>
- 03-08-2011, 07:06 PM #10
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
This stack overflow thread is related
java - Classpath including JAR within a JAR - Stack Overflow
It's the same situation I'm in, right?
maybe I can just separate the jars and add them both to the archive parameter.
- 03-08-2011, 10:59 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
Embedding Database
By shalin.shah in forum JDBCReplies: 1Last Post: 12-12-2010, 06:40 AM -
Embedding Jframe displayin a graph in webpage
By bharath333 in forum Java 2DReplies: 1Last Post: 04-23-2009, 08:12 PM -
Embedding Applet into HTML?
By Unome in forum Java AppletsReplies: 1Last Post: 02-21-2009, 03:40 AM -
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02-08-2009, 06:14 AM -
Embedding Word in an applet
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks