0

从现在开始一个星期,我正在寻找如何制作JProgressBar结果集。请给我一个应用于结果集的进度条示例代码示例?

这是一个带有按钮的示例代码,通过单击它来完成操作。

JButton btnRechercher = new JButton("Rechercher");
    btnRechercher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Connection conn = ConnectionManager.getInstance().getConnection();
            try {
                String sql = "SELECT id, nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE (niveau LIKE ? AND  localisation LIKE ? AND pays LIKE ? AND secteur1 LIKE ?) OR (MATCH (titre_cv1, titre_cv2, titre_cv3) AGAINST (? IN BOOLEAN MODE))";

                PreparedStatement stmt = conn.prepareStatement(sql);
                stmt.setObject(1, ""+comboNiveau.getSelectedItem()+"");
                stmt.setObject(2, ""+comboLocal.getSelectedItem()+"");
                stmt.setObject(3, ""+comboPays.getSelectedItem()+"");
                stmt.setObject(4, ""+comboSecteur.getSelectedItem()+"");
                stmt.setString(5, ""+motCle.getText()+"");

                ResultSet rs = stmt.executeQuery();

                DefaultTableModel model = new DefaultTableModel();
                model.setColumnIdentifiers(new String []{"id","nom","prenom","niveau","localisation","pays","secteur1"}); 
                    while (rs.next()) {
                        model.addRow(new Object[]{rs.getObject("id"),rs.getObject("nom"),rs.getObject("prenom"),rs.getObject("niveau"),rs.getObject("localisation"),rs.getObject("pays"),rs.getObject("secteur1")});
                    }
                    table.setModel(model);
            } catch (Exception e1) {
                System.err.println(e1);
            }
            ConnectionManager.getInstance().close();
        }
    });

我补充说:

class ThreadAvanceBarre extends Thread {

        public ThreadAvanceBarre(JProgressBar ProgressBar){     
        }

        public void run(){
        try {
            Connection conn = ConnectionManager.getInstance().getConnection();

            String sql = "SELECT id, nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE (niveau LIKE ? AND  localisation LIKE ? AND pays LIKE ? AND secteur1 LIKE ?) OR (MATCH (titre_cv1, titre_cv2, titre_cv3) AGAINST (? IN BOOLEAN MODE))";

            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.setObject(1, ""+comboNiveau.getSelectedItem()+"");
            stmt.setObject(2, ""+comboLocal.getSelectedItem()+"");
            stmt.setObject(3, ""+comboPays.getSelectedItem()+"");
            stmt.setObject(4, ""+comboSecteur.getSelectedItem()+"");
            stmt.setString(5, ""+motCle.getText()+"");
            ResultSet rs = stmt.executeQuery();
            DefaultTableModel model = new DefaultTableModel();
            model.setColumnIdentifiers(new String []{"id","nom","prenom","niveau","localisation","pays","secteur1"}); 
            while (rs.next()) {
                model.addRow(new Object[]{rs.getObject("id"),rs.getObject("nom"),rs.getObject("prenom"),rs.getObject("niveau"),rs.getObject("localisation"),rs.getObject("pays"),rs.getObject("secteur1")});
            }
            table.setModel(model);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        ConnectionManager.getInstance().close();
    }
}
4

0 回答 0