1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| package javaapplication10;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import java.awt.Rectangle;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class bar extends JFrame {
final JDialog d = new JDialog(this, "Progress Dialog", true);
private JPanel jContentPane = null;
private JPanel jPanel = null;
int k = 0;
private JButton jButton = null;
private JLabel jLabel = null;
int g;
int nombreLignes;
private JPanel getJPanel() {
if (jPanel == null) {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(131, 37, 111, 40));
jLabel.setText("JLabel");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(10, 7, 266, 109));
jPanel.add(getJButton(), null);
jPanel.add(jLabel, null);
}
return jPanel;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(15, 34, 99, 45));
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//Initialisation de ton g
g=100;
final JProgressBar dpb = new JProgressBar(0, g);
d.add(BorderLayout.CENTER, dpb);
d.add(BorderLayout.NORTH, new JLabel("Progress..."));
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.setSize(300, 75);
Thread t = new Thread(new Runnable() {
public void run() {
//Simulation d'un traitement
for (int i = 0; i <= 100; i++) {
//Mettre ici le traitement
//Augmentation de la progressBar
dpb.setValue(i);
//Un petit sleep histoire d'avoir le temps de voir la progressBar avancer
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(bar.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*
try {
// connecter la bdd
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url = "jdbc:odbc:ODBC1";
String user = "user";
String pass = "pass";
Connection connection = DriverManager.getConnection(url, user, pass);
Statement instruction = connection.createStatement();
String s = ("SELECT COUNT(GPMAT) from GPM");
ResultSet resultat2 = instruction.executeQuery(s);
resultat2.next();
g = resultat2.getInt(1);
System.out.println(" fffffffffffffffffff " + g);
String sql = " select * from GPM ";
ResultSet resultat = instruction.executeQuery(sql);
//
while (resultat.next()) {
k++;
String nom = resultat.getString("GPMAT");
dpb.setValue(k);
}
} catch (Exception ex) {
System.out.println("jjjjjjjjjjj " + ex.getMessage());
ex.printStackTrace();
}
dpb.setValue(k);
try {
Thread.sleep(25);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (dpb.getValue() == g) {
System.exit(0);
}
*/
}
});
t.start();
d.setVisible(true);
}
});
}
return jButton;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bar thisClass = new bar();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public bar() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
} |