-2
I’d like to pick it up, class Botao
, the value that is stored in the variable aux
and compare it with a string in the class Janela
class Botao extends JButton{
public String aux;
Botao(Menu menu, Janela janela) {
this.setText(menu.lista[menu.i]);
menu.i++;
this.setFocusable(false);
this.addActionListener(evt ->{
menu.setVisible(false);
aux = this.getText().toString();
new Janela(this, menu);
});
}
}
class Janela extends JFrame{
String[] lista2 = {"ID", "Name", "BDay", "Menu"};
public javax.swing.JComboBox listaBox = new javax.swing.JComboBox(lista2);
Janela(Botao botao, Menu menu){
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Botao btn = new Botao(menu, this);
this.setSize(500, 600);
this.setLayout(new java.awt.GridBagLayout());
JPanel topo = new JPanel();
topo.setLayout(new GridLayout(1,3));
topo.add(listaBox);
topo.add(new JTextField());
topo.add(new JButton("pesquisar"));
JPanel meio = new JPanel();
meio.setLayout(new GridLayout(6,2));
if(btn.aux == "medico") {
meio.add(new JLabel("Nome"));
meio.add(new JTextField());
meio.add(new JLabel("CPF"));
meio.add(new JTextField());
meio.add(new JLabel("DataNasc"));
meio.add(new JTextField());
meio.add(new JLabel("Telefone"));
meio.add(new JTextField());
meio.add(new JLabel("E-mail"));
meio.add(new JTextField());
meio.add(new JLabel("OBS"));
meio.add(new JTextField());
}
JPanel baixo = new JPanel();
baixo.setLayout(new GridLayout(1,3));
baixo.add(new JButton());
baixo.add(new JButton());
baixo.add(new JButton());
GridBagConstraints gbc = new GridBagConstraints();gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridy = 1;
gbc.gridx = 1;
gbc.weightx = 1;
gbc.weighty = 0.1;
gbc.fill = GridBagConstraints.BOTH;
this.add(topo, gbc);
gbc.gridy = 2;
gbc.gridx = 1;
gbc.weightx = 1;
gbc.weighty = 0.8;
this.add(meio, gbc);
gbc.gridy = 3;
gbc.gridx = 1;
gbc.weightx = 1;
gbc.weighty = 0.1;
this.add(baixo, gbc);
this.setVisible(true);
}
}
class Menu extends JFrame{
int i = 0;
String[] lista = {"medico", "remedio", "adm", "paciente", "enfermeira", "leito", "receita"};
Janela janela;
Botao medico = new Botao(this, janela);
Botao remedio = new Botao(this, janela);
Botao adm = new Botao(this, janela);
Botao enfermeira = new Botao(this, janela);
Botao paciente = new Botao(this, janela);
Botao leito = new Botao(this, janela);
Botao receita = new Botao(this, janela);
Menu(){
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(500, 600);
this.setLayout(new GridLayout(7,1));
this.add(medico);
this.add(remedio);
this.add(adm);
this.add(paciente);
this.add(enfermeira);
this.add(leito);
this.add(receita);
this.setVisible(true);
}
}
class Main{
public static void main(String[] args){
new Menu();
}
}
Thank you very much friend, you just saved my skin, I owe you my kidney, amen
– Natan