Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet not initialized

 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I would classify myself as a "kinda knows whats going on by code reading, but can only fix it with a struggle" level programmer.

I am going through some old classroom material trying to adapt it for use in my new job(they want buttons instead of clicky links). When I compile the following code with NetBeans (I get the use -deprecation message (which I found means: Old bits and pieces)) then execute the..the...thing, sometimes the viewer pops up (the first 2 times "change this, compile, execute")and sometimes it wont(the last 3 times it hasnt).

When the viewer doesnt pop up, a rectangle [](smooshed together) appears on the CoreButton I/O tab.

What terribly simple thing am I missing?

Thank you in advance. I am now going back to the search feature here on the forums.

Added 1pm Central: Here are the console messages I have worked it into:
java.lang.ClassCastException
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Jen R.


import java.awt.*;

public class CoreButton extends Frame {

public CoreButton()
{ setTitle("ButtonTest");
setLayout(new FlowLayout());
add (new Button("Yes"));
add (new Button("No"));
add (new Button("Ok"));
add (new Button("Cancel"));
add (new Button("Abort"));
add (new Button("Retry"));
add (new Button("Ignore"));
} //end corebutton layout
public boolean handleEvent(Event evt)
{ if (evt.id == Event.WINDOW_DESTROY) System.exit(0);
return super.handleEvent(evt);
}

public boolean action(Event evt, Object arg)
{ if (arg.equals("Yes")) setBackground(Color.yellow);
else if (arg.equals("No")) setBackground(Color.blue);
else if (arg.equals("Ok")) setBackground(Color.orange);
else if (arg.equals("Cancel")) setBackground(Color.cyan);
else if (arg.equals("Abort")) setBackground(Color.pink);
else if (arg.equals("Retry")) setBackground(Color.red);
else if (arg.equals("Ignore")) setBackground(Color.white);
else return false;
repaint();
return true;
} //end color changes
public static void main(String[] args)
{ Frame f = new CoreButton();
f.resize(320,200);
f.show();
} //end main

} //end program

[ August 26, 2004: Message edited by: jen sol ]
[ August 26, 2004: Message edited by: jen sol ]
 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried converting the code by following the advice here:
"http://java.sun.com/docs/books/tutorial/post1.0/converting/convertingAWT.html#events" without success. I am still stumped on this one. Any advice?

Thanks again.

Jen R
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u provide your applet code as well so that we can help you as much as we can? I have had a look at the tutorial that you provided above... They all work fine for me...

I think you modify sthing that shouldn't be... Well, if you can provide your applet code, it would be more likely that we can help you with all of our efforts....
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is fine.

And i'm test your code in Applet class follow this :::



Result
It's work fine in appletviewer.



-----------------------


I don't found error.
[ August 26, 2004: Message edited by: Somkiat Puisungnoen ]
 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help so far.

Where do I put the TestApplet? Should I try making it a class of its own? I tried sticking it in here and there, but get a message that it should be declared in it own class. I have also tried extends and implements in various places. At times it seems like I am almost trying to nest classes.

Like I said, I only know enough of this at this point to experience the roller coaster ride (valleys=beating head against the wall in frustration; hilltops=YAY! IT WORKED! Dont know how, but it WORKED!!) of programming in Java. (I do hope someday to be able to take a Java course that can bring me to a point of not having it be such a struggle.)

As it stands this morning, here is my code along with the "error" message:

Code:
import java.applet.Applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CoreButton2 extends Frame //note to self:
//using Applet here
//causes errors in
//the Button part.
{
public CoreButton2()
{ setTitle("ButtonTest");
setLayout(new FlowLayout());
add (new Button("Yes"));
add (new Button("No"));
add (new Button("Ok"));
add (new Button("Cancel"));
add (new Button("Abort"));
add (new Button("Retry"));
add (new Button("Ignore"));
} //end corebutton2 layout

public boolean action(Event evt, Object arg)
{ if (arg.equals("Yes")) setBackground(Color.yellow);
else if (arg.equals("No")) setBackground(Color.blue);
else if (arg.equals("Ok")) setBackground(Color.orange);
else if (arg.equals("Cancel")) setBackground(Color.cyan);
else if (arg.equals("Abort")) setBackground(Color.pink);
else if (arg.equals("Retry")) setBackground(Color.red);
else if (arg.equals("Ignore")) setBackground(Color.white);
else return false;
repaint();
return true;
} //end color changes

public void init(String[] args) {
// TODO Auto-generated method stub
Frame f = new CoreButton2();
f.resize(320, 200);
f.show();
}//end init

} // end class

The Alert Message I get from a regular compile:
Note: C:\Documents and Settings\jenr\Desktop\PIDTree\CoreButton2.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
Finished CoreButton2.

The Error Message I get from Debug:
java.lang.ClassCastException
at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
at sun.applet.AppletPanel.run(AppletPanel.java:298)
at java.lang.Thread.run(Thread.java:534)

Thanks again for helping me get some sort of grip on this.
Jen
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What browser you are using? As well as the JVM?

Are you using some classes that supports by SUN's JVM, but not Mircosoft's if you are using IE?

Nick
 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under Tools>Internet Options>Advanced I have:
Java(Sun):
Java 2v1.4.2_05 for Applet
MS:
Java logging enabled
JIT compiler for virtual machine enabled

When I compile it with javac, I get the message:
"resize(int,int) in java.awt.Component has been deprecated.

Could this be what is holding me up?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Applets forum.
 
Joe Ess
Bartender
Posts: 9340
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An "applet" must extend java.applet.Applet. The error you are getting:

is the JVM signaling that it expected an instance of Applet but you gave it some other class.
Also note that this import:

should be

That's what is causing all those errors when you try to declare CoreButton2 as extending Applet.
 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the pointer, Joe. Now I can wrestle with it. I know I am still missing something that is right uner my nose, I just cant see it yet.

When I extend Applet, my setTitle and Frame f = new CoreButton2() light up red. So I have to figure out a new way of saying that.

Appreciate the help, really I do!

Thanks,
Jen
 
Joe Ess
Bartender
Posts: 9340
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jen sol:

When I extend Applet, my setTitle

Applet's dont have titles, hence there's no setTitle method.


Frame f = new CoreButton2() light up red. So I have to figure out a new way of saying that.

Applets are a particular data type. Frames are a particular, unrelated data type. One cannot create an instance of an Applet and place it in a variable of type Frame.
Just to head off the next two questions:

Applets don't have these two methods either. You can set the size of an applet in the APPLET HTML tag. You should have a gander at the Writing Applets portion of the Java Tutorial.
 
jen sol
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe! Between your explanations (bless you!) and the Components Methods page of the tutorial, my buttons now change the background color like they are supposed to!

Thanks again!
Jen R
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic