K
K
Kirill Romanenko2014-07-11 11:29:48
Java
Kirill Romanenko, 2014-07-11 11:29:48

What's the easiest way to call a new window inside a window?

Guys, you are a pro here, tell me right away - what is the easiest, standard way that I can call a new window with my other buttons from the main window, etc.
Like how the Options window appears in the Game window when you click on the Game Settings button.
I have already created a separate class for the Options, put in the name and all the buttons there, but how is it now easier to call it when clicking on the Options-JButton on top of the game window?
Write something like this?
if (option.isEnabled)
{
Option.setVizible();
}
Or are there points that I need to know about, or are there better ways?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Calc, 2014-07-11
@Calc

settingsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ConfigDialog dialog = new ConfigDialog(frame, config);

                dialog.create();
            }
        });

public void create(){
        GridLayout layout = new GridLayout(4, 2, 8, 8);

        BorderLayout borderLayout = new BorderLayout(GAP, GAP);

        JPanel panel = new JPanel(layout);
        panel.setBorder(BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP));
        panel.setLayout(borderLayout);

        panel.add(createLabels(), BorderLayout.WEST);
        panel.add(createTextFields(), BorderLayout.CENTER);
        panel.add(createButtons(), BorderLayout.SOUTH);

        getContentPane().add(panel);
        pack();
        setLocationRelativeTo(getOwner());
        setVisible(true);
    }

K
Kirill Romanenko, 2014-07-11
@kiralis39

By the way, why is @Override needed? Like I read something like that it overrides everything that was before it?
What will happen without him?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question