Maydayfluffy
Maydayfluffy

Reputation: 427

Changing into new window

What is an efficient method to have a window change into a different window? When the user presses the next button, I would want it to perform another method that would create this second window. What is the appropriate listener class for this scenario?

Upvotes: 1

Views: 95

Answers (2)

Juvanis
Juvanis

Reputation: 25950

An example scenario for your question:

You may have a JFrame which is the starting point of your application, i.e. having single instance, main method, general initialization of components etc. You say you want to change windows. Let these windows be different JPanel objects that each of them are assigned to operate on different tasks. You can add these panels to your main frame. And changing these panels upon certain conditions will make your application capable of navigating between these panels/windows as well. So how to make this happen? Take a look at CardLayout and use it to navigate between your predefined panels on their container frame.

What is the appropriate listener class for this scenario?

Take a look at this post, I have demonstrated CardLayout usage via ActionListener.

Upvotes: 5

Andrew Thompson
Andrew Thompson

Reputation: 168825

What is the appropriate listener class for this scenario?

An ActionListener. See the links already provided in comments, for how to use one.

Upvotes: 3

Related Questions