public class S199_PhoneUI extends JFrame{
JTextField tfName;
JComboBox<String> cmbPhone;
JTextField tfPhone2;
JTextField tfPhone3;
JTextField tfPhone;
public S199_PhoneUI() {
this.setSize(600, 400);
this.setLayout(null);
JLabel lblName = new JLabel("이름");
lblName.setBounds(10, 10, 100, 25);
this.add(lblName);
tfName = new JTextField();
tfName.setBounds(120, 10, 100, 25);
this.add(tfName);
JLabel lblPhone = new JLabel("전화");
lblPhone.setBounds(10, 40, 100, 25);
this.add(lblPhone);
String[] hp = new String[] { "010", "011", "016", "017", "018", "019" };
cmbPhone = new JComboBox<String>(hp);
cmbPhone.setBounds(120, 40, 50, 25);
cmbPhone.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getStateChange() == ItemEvent.SELECTED) {
tfPhone.setText(cmbPhone.getSelectedItem().toString()
+ "-" + tfPhone2.getText()
+ "-" + tfPhone2.getText()
);
}
}
});
this.add(cmbPhone);
tfPhone2 = new JTextField();
tfPhone2.setBounds(180, 40, 50, 25);
this.add(tfPhone2);
tfPhone3 = new JTextField();
tfPhone3.setBounds(240, 40, 50, 25);
this.add(tfPhone3);
tfPhone = new JTextField();
tfPhone.setBounds(300, 40, 100, 25);
this.add(tfPhone);
JButton btnSave = new JButton("저장");
btnSave.setBounds(10, 300, 100, 25);
this.add(btnSave);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new S199_PhoneUI();
}
}