Ciao ragazzi ho un problema ho creato due file ognuno di loro crea due JFrame. Nel primo Frame1 ho creato un toggleButton ora quando il toggleButton e premuto mi visualizza il secondo Frame2 ma quando rilascio vorrei chiudere il secondo Frame2.
codice:
public class Frame1 extends JFrame{
....
JToggleButton Pulsante = new JToggleButton();
...
public Frame1(){
...
Pulsante.addItemListener(new PulsanteItem());
...
}
class PulsanteItem implements ItemListener{
Frame2 riduci = new Frame2();
public void itemStateChanged(ItemEvent e) {
int status = e.getStateChange();
if(status == ItemEvent.SELECTED) {
System.out.println("Tasto Schiacciato");
new Frame2();
}
else
System.out.println("Tasto Rilasciato");
//Qui chiamo tramite un oggetto il metodo contenuto nell'altroframe
riduci.Nascondi();
}
}
}
---------------------------------------------------------------------
public class Frame2 {
JFrame frame = new ResultSetFrame();
public Frame2(){
Visualizza();
}
public void Visualizza(){
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(400,200);
frame.setIconImage(new ImageIcon("Image/frame.png").getImage());
frame.setVisible(true);
}
public void Nascondi(){
frame.setVisible(false);
}
}
Invece di setVisible(false) che metodo dovrei passargli e perche quando rilascio il togglebutton perde il focus ma rimane ancora visibile grazie in anticipo