Dorian Dorian - 1 year ago 69
Java Question

Java navigation approach

I am new to Java and I would like to know which would be the best approach to create my app's navigation.
I will now explain my app functionality and the approach I chose.

Leaving all the networking and other details behind, I will concentrate on the GUI part, since this is what I am here for.

Basically my app does the following :

  1. When you start it, you are presented with a login screen, and 2 buttons(Register and Login).

  2. The sign up screen is a basic register screen with it's accordingly components.

  3. If the users enters correct login information, he will be presented with a view containing some data.

Now, I thought to make a JDialog/JFrame/Frame that is global for the app and when the users clicks a button, remove the previous content of it and "re-paint" new components.

Snippet from my sign up screen :

private JButton signUp;
private final JDialog parent;

signUp = new JButton("Sign Up");
signUp.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Account v = new Account(parent);
// add all the components to the parent frame

By calling
Account v = new Account(parent);
I have passed the global frame(
in my case) to be "repopulated" with other contents using
So my idea is : all the "views" I need to my app should have a "parent" field (which gets the global frame when the constructor is called) on which I add the components I need. Every time, before I call the
method for a view, I will remove all the previous content.
I am not sure this is a good approach since I read about Threads and MVC. On the other hand my approach seems really simple and I am not sure if I should complicate it with multithreading or MVC.

By using my approach I have managed to make a quite flexible UI, I can "play" with the frame's properties (size, focus, enabling,etc.) from any view.

NOTE: If I have not been clear enough, when I say "view" I am referring to the class that receives the
field when created and uses
to add content inside my parent frame.

EDIT: I do not need any code from you guys, just a simple piece of advice. I do this because I don't want further in the development of the app to encounter some serious issues because of my approach on the navigation style.

Answer Source

You can either remove/readd new content calling


Or use CardLayout shwoing actual card with necessary UI.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download