Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet not initializing

 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time writing a applet, and I'm getting an error that it is not initialized. I was pretty sure I did everything the book said to do, so I'm wondering if anyone could take a look at my code and see where I might have done something wrong. The CheckBoxApplet.java file does compile, but the applet does not initialize.
CheckBoxApplet.java

CheckBoxApplet.html

------------------
Thanks, Dianne
 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please send us the exact error message that is thrown in the "Applet Console" of the browser.
As a reminder, you have to put the applet in the same directory as the html (that contains the applet tag) resides.
Another cause may be the POLICY file.
Sabbir
 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I have the applet file and the html file in the same directory. Here is what the screen said:
[error]
C:\myjava\assignment2\problem1>javac CheckBoxApplet.java
C:\myjava\assignment2\problem1>appletViewer CheckBoxApplet.html
java.lang.ClassCastException: CheckBoxApplet
at sun.applet.AppletPanel.createApplet(AppletPanel.java:579)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:515)
at sun.applet.AppletPanel.run(AppletPanel.java:293)
at java.lang.Thread.run(Thread.java:484)
C:\myjava\assignment2\problem1>
[/error]
The applet window itself says "Start: applet not initialized."
In the Browser it doesn't say anything, it's just a grey box.
Also, I don't know what you mean by Policy file.
------------------
Thanks, Dianne
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dianne,
In order to create an applet you need to subclass 1 of 2 classes:
java.awt.Applet
or
javax.swing.JApplet
Which of these two have you subclassed?
Regards,
Manfred.
 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by subclass? I don't remember my teacher saying anything about a subclass.
------------------
Thanks, Dianne
 
peter johansson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to run a class as an applet it must be declared public(as you have done) also it must subclass java.applet.Applet(you could also use the JApplet).
regards,
/Peter
Originally posted by Dianne Calhoun:
[B]This is my first time writing a applet, and I'm getting an error that it is not initialized. I was pretty sure I did everything the book said to do, so I'm wondering if anyone could take a look at my code and see where I might have done something wrong. The CheckBoxApplet.java file does compile, but the applet does not initialize.
CheckBoxApplet.java

CheckBoxApplet.html

[/B]

 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dianne,
Looks like you have created an app instead of Applet. You may run your app using the "java app_name" command.
Sabbir
 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I see now. I had to change the CheckBoxApplet extends JFrame to CheckBoxApplet extends JApplet. It works great now.
------------------
Thanks, Dianne
 
Michael Oates
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did what you said, and the applet still won't initialize. What am I doning wrong?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> What am I doning wrong?

to start, posting to an 11-year-old post, with a number of replies already,
cuts down the number of people that will see your post.

much better to start your own topic (use the same subject if you like),
then post the code you've tried and explain the problem, or the steps to recreate the problem,
and I'm sure you'll get an answer in a reasonably quick time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic