Results 1 to 13 of 13
- 07-10-2011, 11:15 PM #1
new to Java applets... where to start??
I'm pretty new to Java overall, but I've built a JFrame app before, so I kinda know the basics to it.
However, I've read a few Applet tutorials and caught a few tips and info from all of them. For example, I've seen I don't need a "main" method but an "init" and "run" methods (don't know if I need both, though). What I don't know is exactly how to implement them.
I've been reading http://book.javanb.com/jfc-swing-tut...7lev1sec1.html but this talks about threads... Do I absolutely need threads?
Anyway, what I'm looking for is some resource that'll teach me how to build Swing Applets (most of the stuff I find out there is about awt applets) from scratch, since my attempts at building one aren't working.
Thanks!
- 07-10-2011, 11:51 PM #2
No you do not need to use Threads.
Go to this site:The Really Big Index
and Find Applets for lots about writing applets from the Java group.
- 07-13-2011, 02:13 AM #3
Thanks Norm!
I managed to start building my applet. But when I try to include it in a html file (I'm reading Deploying an Applet (The Java™ Tutorials > Deployment > Java Applets)) I just can't seem to make it simple and clean. It says something about compiling my applet into a jar file and then building a jnlp file that needs a main-class attribute to load the class containing the "main" method... but as far as I've seen, applets don't have a main method but an init method...
So basically, how do I use my applet? :P
Thanks again!
- 07-13-2011, 02:32 AM #4
For a first version of your applet, you won't need a jar file or any of the jnlp stuff. That is for deployment after you get it working and want to share it.
Put all the applet's class files, hopefully there are only a few, in a test folder.
Create an HTML file with an applet tag:
<APPLET code="THE CLASS NAME HERE" width=500 height=500>
</APPLET>
and open the html file in a browser.
Set the width and height for what your applet needs.
- 07-13-2011, 05:11 AM #5
Thanks again :)
The reason I was trying the jar file thing is that I had tried the <applet> tag you mentioned but I wasn't successful.
My applet runs normally when I press "run" in Eclipse, but it doesn't seem to work in my html file (I see a white empty rectangle where the applet should be showing).
I have 2 classes, one of which has the init method and instantiates the other class, which contains all the GUI components. I built both .class files and then included the one that contains the init method in my <applet> tag, like this:
<html>
<body bgcolor=#000000>
<APPLET code="Inicio.class" width=750 height=400></APPLET>
</body>
</html>
I tried without the ".class" bit just in case, but still doesn't work. What am I doing wrong?
- 07-13-2011, 01:53 PM #6
Look at the browser's java console for error messages.What am I doing wrong?
Leave off the .class
Are the html and class files in the testing folder?
- 07-13-2011, 04:12 PM #7
Is there a package statement at the top of the class that extends JApplet?
db
- 07-13-2011, 09:40 PM #8
The java console gives the following information:
Exception in thread "thread applet-Inicio.class-3" java.lang.NoClassDefFoundError: Inicio$1
at Inicio.init(Inicio.java:15)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
This is what my main class has (class name is "Inicio"):
import javax.swing.SwingUtilities;
import javax.swing.JApplet;
public class Inicio extends JApplet{
private static final long serialVersionUID = 1L;
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
}
});
setSize(750, 400);
createGUI();
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
private void createGUI() {
//Create and set up the content pane.
Ventana panel = new Ventana();
panel.setOpaque(true);
setContentPane(panel);
}
}
And the other class extends from JPanel and has a few components that show normally when I run my applet within Eclipse.
- 07-13-2011, 09:42 PM #9
(edit - I got an error saying my message hadn't been posted, so I reposted it and found out it was here twice :P)
- 07-13-2011, 09:59 PM #10
Did you copy ALL of the .class files to your test folder?ava.lang.NoClassDefFoundError: Inicio$1
The $1 on the end of the class name: Inicio$1
is for an inner anonymous class, probably the new Runnable() {
Can you explain the steps you took for this test?
- 07-14-2011, 02:00 AM #11
Oh... I have the test.html, Ventana.class and Inicio.class files in my folder, but not the Runnable.class. In fact, I just copied that bit from the tutorial, but I didn't quite get why I have to use SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
}
I just open the html file, but it seems I need some more classes in the folder where the html file lives...?
- 07-14-2011, 02:58 AM #12
You need ALL of the class files that are created when you compile your source program.
- 07-14-2011, 04:43 AM #13
Similar Threads
-
Start Swing GUI program by Java Web Start with IE in Eclipse debug mode
By albertkao in forum EclipseReplies: 1Last Post: 01-18-2011, 06:27 PM -
All applets fail to start
By dathoedezt in forum Java AppletsReplies: 4Last Post: 01-13-2011, 11:25 PM -
Java Applets
By kevinnrobert in forum Java AppletsReplies: 1Last Post: 04-02-2010, 01:16 PM -
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM -
Applets (init, start, stop, destroy)
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks