0

I have a main menu, when need to see the data added pop up a new JFrame with a ok button, i add a listener to it, when i hit ok to close it, it close the main menu and keep the GUI with the results opens, i just one to close the result gui, not the main menu, i try dispose() and of course system.out(0), but it close all

public void GuiResultados(Persona persona, Abs abs){

    JLabel titulo = new JLabel();  
    titulo.setBounds(5,8,700,30); 
    titulo.setText("Resultados");
    JFrame frame= new JFrame();  
    JButton button = new JButton("Ok"); \\button create
    CloseListener closelistener = new CloseListener(); \\closelistener process
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    button.setVisible(true); \\button visible
    frame.setTitle("Datos de entrenamiento");
    JTextArea area=new JTextArea();
    area.append("Edad: "+ persona.getEdad() + "\n");
    area.append("Estatura(m): " + persona.getTamano() + "\n");

    area.append("Cantidad de calorias quemadas en todas las series:" + totalCaloriasQuemadasAbs + "\n");


    button.setBounds(150,395,100,30);
    area.setEditable(false);
    area.setBounds(20,30, 350,350);  
    frame.add(area);  
    frame.add(button);

    button.addActionListener(closelistener); // calling the listener
    frame.add(titulo);
    frame.setSize(410,500);  
    frame.setLayout(null);  
    frame.setVisible(true); 
}

private class CloseListener implements ActionListener{

    public void actionPerformed(ActionEvent e) {

        dispose(); //not closing main window, not the gui where the button is
    System.out.println("Frame Closed. ");
    }
}
achAmháin
  • 4,176
  • 4
  • 17
  • 40
bacotico
  • 17
  • 4

1 Answers1

0

I found the solution, sorry, if someone needed is these one

private class CloseListener implements ActionListener{

    public void actionPerformed(ActionEvent e) {
        Window win = SwingUtilities.getWindowAncestor((Component) e.getSource());
        win.dispose();
    System.out.println("Frame Closed. ");
    }
}
bacotico
  • 17
  • 4