Java:如何显示Hello World!单击按钮后
我想了解如何在 Java 中转到下一个“框架或屏幕”。
我正在学习 Java 并让 Hello World 应用程序正常工作, 我的下一步是有一个按钮,单击它后我想要 你好世界!出现。
所以首先是按钮,然后是下一个“框架”中的 Hello World 我称其为框架,但不知道 Java 中如何称呼它。 我使用windows7和记事本顺便问一下
我该怎么做?
I would like to learn how you go to a next 'frame or screen' in Java.
I'm learning Java and got the Hello World App working,
My next step is to have a button and after its being clicked I want the
Hello World! to appear.
So first the button and then the Hello World in the next 'frame'
I call it frames but don't know how it's called for Java.
I use windows7 and notepad by the way
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,找到适合您的挥杆教程。有很多,例如 this 和 this (首先在 google 上...)
基本上,您需要在
JPanel 中放置一个
,然后将JButton
JPanel
放入主JFrame
中。另外,要显示“hello world”屏幕,您需要创建显示它的 ActionListener 并将其添加到您的按钮。First, find a swing tutorial that fits you. There are many, such as this and this (first on google...)
Basically, you need to put a
JButton
in aJPanel
and then put theJPanel
in your mainJFrame
. Also, to display the "hello world" screen you need to create ActionListener that displays it and add it to your button.有很多选项,但在这种情况下,您可能希望使用 CardLayout< /a>.
There are many options, but in this case you might look to use a CardLayout.
这里只是一个建议,但我发现在学习 java 时使用面向 Java 的 IDE 非常有用(在我的例子中是 JDevelopepr)。你应该尝试一下。现在要回答您的问题,您必须调用按钮的 AddMouseListener 方法并向其传递一个实现 MouseListener 的类的对象。请参阅 Oracle 网站 了解更多信息,因为这将是相当长的帖子。
Just a suggestion here, but I found it very useful to use a Java oriented IDE when learning java (JDevelopepr in my case). You should try it out. Now to answer your question, you will have to call your button's AddMouseListener method and pass it an object of a class that implements MouseListener. Refer to the Oracle website for more info as this would be a rather long post.