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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Dimension;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.border.TitledBorder;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.event.UndoableEditEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Font;
import javax.swing.JComboBox;
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) {
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()
{
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;
}
} |
Partager