如何让小程序接受用户特定的输入?
我有一个关于java小程序的问题。我创建了一个java小程序,这是一个棋盘游戏,它可以有一个2*2数组,默认情况下行号和列号都设置为9。
现在我想稍微扩展我的小程序,用户可以在命令行上指定他们想要的大小,然后小程序类将创建一个具有相应大小的小程序。
我尝试在小程序类中添加一个构造函数,但 Eclipse 抱怨,我还尝试了另一个类,它将创建该小程序的一个实例,其大小作为实例变量,但它不起作用。
有人可以帮助我在哪里放置一个可以处理用户指定的板尺寸的 main() 方法,然后相应地在我的小程序类中创建一个数组吗?
多谢。
抢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该使用
main()
方法:那是 Java 应用程序 入口点。由于您已经有一个 Java 小程序,因此只需对其进行处理,以便它询问用户板尺寸等,然后再继续使用您已有的内容。另请参阅
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
当小程序运行时,
main()
不会被执行。仅Applet #init()
将被运行。只需弹出一个 SwingJOptionPane
类型为JOptionPane 的
.QUESTION_MESSAGE
要求用户输入。The
main()
won't be executed when the applet runs. Only theApplet#init()
will be run. Just pop a SwingJOptionPane
of typeJOptionPane.QUESTION_MESSAGE
which asks for user input.