[5784] in java-interest
HELP - Extending the Applet class
daemon@ATHENA.MIT.EDU (Mike Wooding)
Mon Feb 26 18:10:58 1996
Date: Mon, 26 Feb 1996 13:44:03 -0800
From: Mike Wooding <woodinmi@earthlink.net>
To: java-interest@java.Eng.Sun.COM
/// HELP - I am attempting to learn how to create multiple classes in
//Java Applets. The enclosed code's goal is to create a Panel with 2
//buttons labelled Previous and Next. Then, in a seperate class I am
//trying to create another panel with 5 buttons. I then want this panel
//to be added to the applet's panel "North" of the Previous and Next
//Buttons. When I attempt to run the code I get the error below. (I know
//that what I'm doing can be done other ways but I am trying to learn
//how to extend the class hierarchy within Applets so that I can
//override events in objects other than the Applet derived class).
//THANKS FOR ANY ADVICE, HELP, or SAMPLES !!! woodinmi@earthlink.net
//----------------------------------------------------------------
// ERROR WHEN RUN FROM APPLETVIEWER
//D:\html>appletviewer Page1.html
//java.lang.NoClassDefFoundError: OptionPanel
// at Page1.init(Page1.java:52)
// at sun.applet.AppletPanel.run(AppletPanel.java:243)
// at java.lang.Thread.run(Thread.java:289)
//-----------------------------------------------------------------
import java.awt.*;
import java.net.URL;
import java.applet.*;
class OptionPanel extends Panel {
Button b[]; // Array of unknown number of buttons
Label lbl = new Label("Option Panel Class");
public OptionPanel() {
System.out.println("OptionPanel Constructor");
}
public boolean makeButtons() {
for(int i = 0; i < 5; i++){
b[i]=new Button("Button" + i);
add(b[i]);
}
add(lbl);
return true;
}
}
public class Page1 extends Applet {
CardLayout c;
Panel p;
public void init() {
setLayout(new BorderLayout());
add("South", p=new Panel());
p.add(new Button("Next"));
p.add(new Button("Previous"));
add("Center", p = new Panel());
p.setLayout(new BorderLayout());
OptionPanel optPanel = new OptionPanel();
optPanel.setLayout(new FlowLayout());
optPanel.makeButtons();
p.add("North",optPanel);
}
public boolean action(Event evt, Object arg){
showStatus(((Button)evt.target).getLabel());
return true;
}
public boolean mouseDown(Event evt,int x, int y){
showStatus("X Position = " + x + "Y == " + y);
return true;
}
} // End of Page1 Applet Class Definition
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com