1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| public class HostChoice extends JFrame {
private JComboBox hostType;
private JLabel hostTypeLabel;
private String choice;
private boolean buttonOk =false;
public HostChoice() {
}
public void SelectChoice() {
this.setTitle("Connection");
this.setSize(300, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
// combobox
JPanel panHostType = new JPanel();
panHostType.setBackground(Color.white);
panHostType.setPreferredSize(new Dimension(100, 100));
panHostType.setBorder(BorderFactory.createTitledBorder("Host Wahl"));
hostType = new JComboBox();
hostType.setPreferredSize(new Dimension(100, 30));
hostType.addItem("QQ");
hostType.addItem("QS");
hostType.addItem("Test");
hostTypeLabel = new JLabel("Host : ");
panHostType.add(hostTypeLabel);
panHostType.add(hostType);
// bouton
JPanel control = new JPanel();
JButton okBouton = new JButton("OK");
okBouton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// items selected
setChoice((String) hostType.getSelectedItem());
buttonOk = true;
}
});
JButton cancelBouton = new JButton("Back");
cancelBouton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
setVisible(false);
}
});
control.add(okBouton);
control.add(cancelBouton);
this.getContentPane().add(panHostType, BorderLayout.CENTER);
this.getContentPane().add(control, BorderLayout.SOUTH);
this.setVisible(true);
}
public boolean isButtonOk() {
return buttonOk;
}
public void setButtonOk(boolean buttonOk) {
this.buttonOk = buttonOk;
}
public void setChoice(String choice) {
this.choice = choice;
}
public String getChoice() {
return choice;
}
} |
Partager