PDA

View Full Version : program in java


Aymen++
03-06-2003, 10:09 AM
i have the following code:

//: Button1.java
// Putting buttons on an applet
import java.awt.*;
import java.applet.*;
public class Button1 extends Applet {
Button
b1 = new Button("Button 1"),
b2 = new Button("Button 2");
public void init() {
add(b1);
add(b2);
}
} ///:~

when i compile it, everything going alright, but when i exute it the following error appear:
exception in thred main java.lang.nosuchmethoderror: main
why?

bcarl314
03-06-2003, 12:52 PM
don't you need the

public class void main(String args[])

class to run an applet? And an init() method?

Aymen++
03-06-2003, 04:13 PM
how can i do it?

Jason
03-06-2003, 10:41 PM
you should be able to add a
public void main( ) {
...
...
}
just before the last bracket so that it is still apart of the class Applet you are using but you already have an init( ) and the main goes below that cause that is the first thing that java will look at.

Jason