简体   繁体   中英

Java: How to show Hello World! after button has been clicked

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?

有很多选项,但是在这种情况下,您可能希望使用CardLayout

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 a JPanel and then put the JPanel in your main JFrame . Also, to display the "hello world" screen you need to create ActionListener that displays it and add it to your button.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM