tags:

views:

16

answers:

2

Hello there.

I have a question on the java applet.I've created a java applet,which is a board game,that can have a 2*2 array with row number and column number both set to 9 by default.

Now I want to extend my applet a bit,that the user can specify the size they want on the command-line,then the applet class will create an applet with correspoding size.

I try to add a constructor in the applet class,but the Eclipse complains,I also tried another class,which will create an instance of this applet with size as an instance variable,but it is not working.

Could anyone help me a little bit on where to put a main() method that can take care of user-specified board sized,then create an array in my applet class accordingly?

Thanks a lot.

Rob

+1  A: 

You shouldn't be using a main() method: that's a Java application entry point. Since you already have a Java applet, just work on it so that it asks users for board size etc, before continuing on with what you already have.

See also

polygenelubricants
+1  A: 

The main() won't be executed when the applet runs. Only the Applet#init() will be run. Just pop a Swing JOptionPane of type JOptionPane.QUESTION_MESSAGE which asks for user input.

public void init() {
    String answer = JOptionPane.showInputDialog(null, "Your question here", "Dialog title here", JOptionPane.QUESTION_MESSAGE);
    // ...
}
BalusC