1
I want to create two screens, one registers the values of Jcombobox and the other I use the values. I can get the Combobox back but there’s no value.
Class of register
public class Combo extends JFrame{
private JButton ok,proxima;
private JTextField texto;
private JComboBox<String> meucombo;
public JComboBox getMeucombo() {
return meucombo;
}
Combo() {
super("ComboBox");
mCombo();
}
private void mCombo() {
setLayout(new BorderLayout());
acaoBotao acao = new acaoBotao();
outroBotao outroBotao = new outroBotao();
meucombo = new JComboBox<String>();
proxima = new JButton("proxima");
proxima.addActionListener(outroBotao);
ok = new JButton("OK");
ok.addActionListener(acao);
texto = new JTextField();
add(meucombo, BorderLayout.NORTH);
add(texto, BorderLayout.CENTER);
add(ok, BorderLayout.SOUTH);
add(proxima,BorderLayout.EAST);
}
private class acaoBotao implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
meucombo.addItem(texto.getText());
texto.setText("");
}
}
private class outroBotao implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
Teste teste = new Teste();
teste.setVisible(true);
}
}
}
Other class
public class Teste extends JFrame {
Teste(){
super("teste");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(600,600);
setVisible(true);
Combo combo = new Combo();
JComboBox mcombo = combo.getMeucombo();
JFrame frame = new JFrame();
frame.setLayout(new FlowLayout());
add(mcombo);
}
}
Thank you for the reply friend, it is only a room activity so do not need bank. I thank you
– Rodolfo Allesson
@Rodolfoallesson ah yes, in this case this solution meets well :) If the answer served you can mark it as accepted by clicking on
v
next to her.– user28595