Efficiently design method to construct a Java GUI?

79 views Asked by At

This is for a school project where we implement a GUI for our previously made system, problem is our teacher only taught us JFrame.

So in the end, what I have is, a JFrame for the MainScreen, and when I click a button to go the the OtherScreen, it will simply close one screen and open another, in the default position, which isn't ideal obviously :

// @ MainScreen :
otherScreenButton.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent ae) {
        MainController.otherScreen();
    }
});

// @ MainController :

public void otherScreen(){
    mainScreen.setVisible(false);
    otherScreen.setVisible(true);
}

My question is, how programmers go about doing GUIs? Adding JPanels inside a main JFrame and setting them visible/not visible on demand? If someone could also provide a link with more detailed information that would be great.

1

There are 1 answers

1
almightyGOSU On BEST ANSWER

Take a look at CardLayout, it will help you with 'switching screens'.

Here's the documentation.