Так что я пытаюсь создать простой GUI, в котором есть возможность ввода нескольких входов. Я хочу, чтобы существовало главное меню GUI и вход GUI. Вопрос в том, как сделать так, чтобы основной GUI исчезал при выборе «вход», и снова появлялся при выборе «возврат в главное меню»?
Вот мое главное меню (незаконченное)
public class MainGUI extends JFrame{
private JButton insert, find, browse, create;
public MainGUI(String name) {
super(name);
setLayout(null);
insert = new JButton("Insert");
find = new JButton("Find");
browse = new JButton("Browse");
create = new JButton("Create Tree From File");
insert.setBounds(25, 200, 100, 30);
find.setBounds(125, 200, 100, 30);
browse.setBounds(225, 200, 100, 30);
create.setBounds(325, 200, 200, 30);
setVisible(true);
setSize(600, 300);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(insert);
add(find);
add(browse);
add(create);
insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//opens the input GUI window
InputGUI input = new InputGUI("Input GUI");
/*I was thinking of adding an if statement here, but it turns
*out that the if statement executes immediately after the inputGUI is made...
*/
}
});
//more action listener stuff here
}
public static void main (String [] args) {
MainGUI gui = new MainGUI("Main Window");
}
}
... и вот вход GUI класс (незаконченное)
private JButton insert, ret;
public InputGUI(String name) {
super(name);
setLayout(null);
insert = new JButton("Insert");
ret = new JButton("Return to Main Window");
insert.setBounds(50, 100, 100, 30);
ret.setBounds(150, 100, 200, 30);
setVisible(true);
setSize(400, 200);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(insert);
add(ret);
ret.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if(cmd.contentEquals("Return to Main Window")) {
dispose();
//how can i detect from the main menu gui that this was disposed?
}
}
});
//more action listener stuff
}
public static void main (String [] args) {
InputGUI gui = new InputGUI("Input Window");
}
}
Любая помощь приветствуется!