How to let applet take user specific input?
I have a question on the java applet.I've created a ja开发者_如何学JAVAva 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
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
- Wikipedia/Java Web Start - the now recommended framework as an alternative to Java applets
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);
// ...
}
精彩评论