como crio outro evento para o botão sair??
public class Principal implements ActionListener {
private JFrame frame1;
public JButton btn_ENTRAR;
public JButton btn_SAIR;
private JFrame frame2;
private boolean ligado =true;
public Principal() {
janelas();
}
public void janelas() {
this.frame1 = new JFrame();
this.frame1.setTitle("Janela 1");
this.frame1.setPreferredSize(new Dimension(400, 400));
this.frame1.pack();
this.frame1.setLayout(null);
this.frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame1.setLocationRelativeTo(null);
this.frame1.setVisible(true);
this.frame2 = new JFrame();
this.frame2.setTitle("Janela 2");
this.frame2.setPreferredSize(new Dimension(400, 400));
this.frame2.pack();
this.frame2.setLayout(null);
this.frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame2.setLocationRelativeTo(null);
this.frame2.setVisible(false);
componentes();
}
public void componentes() {
this.btn_ENTRAR= new JButton("ENTRAR!");
this.btn_ENTRAR.setBounds(100,100,100,30);
this.btn_ENTRAR.addActionListener(this);
this.frame1.add(btn_ENTRAR);
//
this.btn_SAIR= new JButton("SAIR!");
this.btn_SAIR.setBounds(100,100,100,30);
this.frame2.add(btn_SAIR);
}
public static void main(String[] args) {
new Principal();
}
public void texte() {
}
@Override
public void actionPerformed(ActionEvent ac) {
this.frame1.setVisible(false);
this.frame2.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ac) {
this.frame1.setVisible(true);
this.frame2.setVisible(false);
}
}
amo esse Fórum, valew brother.