Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.swing.JCheckBox;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- public class RemoverFed extends JPanel {
- int count;
- public RemoverFed(){
- try {
- this.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.gridx = 0;
- c.gridy = 0;
- JButton botao = new JButton();
- JButton voltar = new JButton();
- voltar.setText("Voltar");
- voltar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JanelaPrincipal.getInstance().trocaPainel(new JanelaInstrucoes());
- }
- });
- botao.setText("Cadastrar nova federação");
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/projetoserio?user=root&password=root");
- java.sql.Statement stmt = conn.createStatement();
- ResultSet teste = stmt.executeQuery("Select count(nome) from federacao;");
- while (teste.next()) {
- count = teste.getInt(1);
- }
- ResultSet federacoes = stmt.executeQuery("Select nome from federacao;");
- JCheckBox feds[] = new JCheckBox[count];
- int i=1;
- while (federacoes.next()){
- feds[i-1].setText(federacoes.getString(1));
- c.gridy++;
- this.add(feds[i-1], c);
- i++;
- }
- botao.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- c.gridwidth = 0;
- c.gridy++;
- this.add(botao, c);
- c.gridy++;
- this.add(voltar, c);
- } catch (ClassNotFoundException e2) {
- e2.printStackTrace();
- } catch (SQLException e2) {
- e2.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement