Bom galera Tenho minha classe CadastroBairroview
que contem os Objetos Combobox UF e combobox Municipios
private JComboBox<Object> ufJComboBox;
private JComboBox<Object> municipioJComboBox;
private JTextField nomeJTextField;
private JTable bairrosJTable;
private JButton okJButton;
private Object aAlterar = null;
private BairroService service;
private BairroEscolherMunicipioAction view;
private BairroEscolherUfAction view2;
public CadastroBairroView(JFrame mainView) {
super();
this.initComponents();
this.initPainel();
this.initPopupMenu();
this.initListeners();
this.initServices();
this.initcombobox();
this.setTitle("[IMPACTA] Cadastro de bairros");
this.setSize(630, 320);
this.setResizable(false);
this.setLocationRelativeTo(mainView);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.setModalityType(ModalityType.DOCUMENT_MODAL);
this.setAlwaysOnTop(true);
this.setModal(true);
}
private void initcombobox() {
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
Connection connection = (Connection) DriverManager.getConnection(
"jdbc:mysql://localhost:3306/cliente-db", "impacta",
"impacta");
Statement query = (Statement) connection.createStatement();
String sql = "SELECT * FROM municipio ORDER BY nm_municipio ";
ResultSet rs = query.executeQuery(sql);
List<Municipio> lisMunicipios = new ArrayList<Municipio>();
while (rs.next()) {
Municipio municipio = new Municipio();
//municipio.setNome(rs.getString("id_uf"));
//ufJComboBox.addItem(rs.getString("id_uf"));
municipio.setId(rs.getInt("id_municipio"));
municipioJComboBox.addItem(rs.getObject("nm_municipio"));
lisMunicipios.add(municipio);
}
} catch (SQLException cause) {
cause.printStackTrace();
JOptionPane.showMessageDialog(null, "Não foi possivel Carregar");
}
}
[color=red]Depois disso tem minha classe BairroEscolherUFAction[/color]
public class BairroEscolherUfAction implements ActionListener {
private JComboBox<Object> ufJComboBox;
private JComboBox<Object> municipioJComboBox;
private MunicipioService municipioService;
private CadastroBairroView view;
private CharSequence nome;
public BairroEscolherUfAction(JComboBox<Object> ufJComboBox,
JComboBox<Object> municipioJComboBox, CadastroBairroView view) {
super();
this.ufJComboBox = ufJComboBox;
this.municipioJComboBox = municipioJComboBox;
this.municipioService = new DefaultMunicipioService();
this.view = view;
}
@Override
public void actionPerformed(ActionEvent euf) {
UFVO uf = (UFVO) view.getUfJComboBox().getSelectedItem();
view.getUfJComboBox().removeAll();
view.getUfJComboBox().addItem(' ');
Connection connection = null;
PreparedStatement query = null;
ResultSet rs = null;
String sql = null;
if (uf.isSelecionado()) {
view.getMunicipioJComboBox().equals(sql);
}
try {
connection = (Connection) DataSource.getConnection();
sql = "SELECT bairro.id_bairro,bairro.nm_bairro,municipio.id_municipio,municipio.nm_municipio FROM bairro"
+ "INNER JOIN municipio "
+ "ON municipio.id_municipio = bairro.municipio_id"
+ "WHERE municipio.id_uf LIKE ? AND bairro.nm_bairro =?";
// "WHERE bairro.nm_bairro LIKE ? AND municipio.id_uf=?
System.out.println(sql);
query = (PreparedStatement) connection.createStatement();
rs = query.executeQuery(sql);
try {
while (rs.next()) {
view.getMunicipioJComboBox().addItem(sql);
}
} catch (Exception e) {
}
} catch (Exception e) {
}
}
[color=green] em seguida tem a classe BairroEscolherMunicipioAction[/color]
private static final long serialVersionUID = 4275902503798323453L;
/**
*
*/
private static final CharSequence nome = null;
private JComboBox<Object> municipioJComboBox;
private JTable bairrosJTable;
private CadastroBairroView view;
private BairroEscolherUfAction view2;
public BairroEscolherMunicipioAction(JComboBox<Object> municipioJComboBox,
JTable bairrosJTable, CadastroBairroView view) {
super();
this.municipioJComboBox = municipioJComboBox;
this.bairrosJTable = bairrosJTable;
this.view = view;
}
@Override
public void actionPerformed(ActionEvent em) {
DefaultBairroDAO dao = new DefaultBairroDAO();
if (em.getSource().equals(em)) {
view.getUfJComboBox().getSelectedItem().equals(dao);
view.getMunicipioJComboBox().getSelectedItem().equals(dao);
}
Mesmo assim não consigo fazer as duas combobox Converarem
Ao clicar na UF sp aparecer apenas os Municipios de SP
Só falta isso pra eu finalizar meu projeto e estou batendo cabeça a dias
Se alguem poder me ajudar eu agradeceria bastante