I currently have two buttons in a JFrame
: one to save and the other to update. In other JFrame
, I have to register and edit.
When I click on the register, I want the save to be on and update off, and when to edit, vice versa. I know I have to use meuJbutton.setEnabled(true/false)
methods, but I do not know how and where to formulate the conditional to activate / deactivate the buttons. I tried something like
The 2 jFrames are as follows:
Main Screen:
public class TelaPrincipal extends javax.swing.JFrame {
public int salvar;
public TelaPrincipal() {
initComponents();
this.setResizable(false);
this.setLocationRelativeTo(null);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
new Cadastro().setVisible(true);
dispose();
salvar = 1;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
new Cadastro().setVisible(true);
dispose();
salvar = 0;
}
}
Signing up:
public class Cadastro extends javax.swing.JFrame {
TelaPrincipal t = new TelaPrincipal();
public Cadastro() {
this.setResizable(false);
initComponents();
this.setLocationRelativeTo(null);
if (t.salvar == 1){
jButton1.setEnabled(true);
jButton3.setEnabled(false);}
else{
jButton1.setEnabled(false);
jButton3.setEnabled(true);
} //no caso o botão 1 sempre está desligado e o 3 ligado não importa o valor de salvar.
}
But it did not work. I'm out of ideas. I'm using Netbeans own tools.