انا عندي اثنين من ال combobox واحدة للدول وواحدة للمدن انا وهما الإثنين بيجيبوا البيانات من قاعدة البيانات بس كنت بسأل اذا في حد ممكن يساعدني في انه لما اختار من ال combobox بتاعت الدول يظهرلي في ال combobox المدن المدن الخاصة بالدولة اللي أنا عايزها وشكرا زانا هسيب محاولاتي
contentPanel.add(countryLabel);
countryComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
countryComboBox = (JComboBox) e.getSource();
}
});
countryComboBox.setBounds(354, 66, 114, 20);
contentPanel.add(countryComboBox);
sateLabel.setBounds(484, 69, 30, 14);
contentPanel.add(sateLabel);
stateComboBox.setBounds(515, 66, 97, 20);
contentPanel.add(stateComboBox);
cityLabel.setBounds(311, 98, 23, 14);
contentPanel.add(cityLabel);
cityComboBox.setBounds(335, 95, 133, 20);
contentPanel.add(cityComboBox);
landPhoneLabel.setBounds(10, 130, 100, 14);
contentPanel.add(landPhoneLabel);
contentPanel.add(landPhoneTextField);
mobilePhoneNumberLabel.setBounds(259, 130, 107, 14);
contentPanel.add(mobilePhoneNumberLabel);
contentPanel.add(mobilePhoneTextField);
emailLabel.setBounds(10, 162, 32, 14);
contentPanel.add(emailLabel);
contentPanel.add(emailTextField);
departmentLabel.setBounds(10, 193, 91, 14);
contentPanel.add(departmentLabel);
departmentComboBox.setBounds(103, 190, 247, 20);
contentPanel.add(departmentComboBox);
jobTitelLabel.setBounds(10, 224, 44, 14);
contentPanel.add(jobTitelLabel);
jobComboBox.setBounds(55, 221, 194, 20);
contentPanel.add(jobComboBox);
salaryLabel.setBounds(259, 224, 34, 14);
contentPanel.add(salaryLabel);
contentPanel.add(salaryTextField);
qualificationLabel.setBounds(10, 255, 66, 14);
contentPanel.add(qualificationLabel);
qualificationComboBox.setBounds(79, 252, 223, 20);
contentPanel.add(qualificationComboBox);
userRoleLabel.setBounds(10, 293, 50, 14);
contentPanel.add(userRoleLabel);
userRoleComboBox.setBounds(62, 290, 140, 20);
contentPanel.add(userRoleComboBox);
usernameLabel.setBounds(10, 321, 52, 14);
contentPanel.add(usernameLabel);
contentPanel.add(usernameTextField);
passwordLabel.setBounds(10, 352, 50, 14);
contentPanel.add(passwordLabel);
passwordField.setBounds(60, 349, 171, 20);
contentPanel.add(passwordField);
repasswordLabel.setBounds(10, 381, 67, 14);
contentPanel.add(repasswordLabel);
repasswordField.setBounds(80, 378, 152, 20);
contentPanel.add(repasswordField);
separator.setBounds(1, 412, 632, 8);
contentPanel.add(separator);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
setCountryComboboxData();
setStateComboboxData();
}
private void setCountryComboboxData() {
Connection conn = Manager.getConnection();
countryComboBox.setModel(countryModel);
String countrySql = "select * from country";
try {
// countrySql = "select * from country";
PreparedStatement ps = conn.prepareStatement(countrySql);
ResultSet rs = ps.executeQuery();
// int count = 0;
while (rs.next()) {
// count++;
countryModel.addElement(rs.getString("name"));
}
} catch (Exception e) {
;
}
}
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String) selected[0]);
}
private void setStateComboboxData() {
Connection conn = Manager.getConnection();
stateComboBox.setModel(stateModel);
try {
String str = "select id from country where name ="
+ countryComboBox.getSelectedItem().toString();
String stateSql = "SELECT name FROM state WHERE country_id =" + str;
PreparedStatement ps = conn.prepareStatement(stateSql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
stateModel.addElement(rs.getString("name"));
}
} catch (Exception e) {
;
}
}
}


