import java.awt.* ; import javax.swing.* ; import java.awt.event.* ; public class TestProgress extends JFrame implements ActionListener { public JProgressBar progressBar ; private JButton button ; private boolean end = false ; public TestProgress() { super( "JProgressBar test" ) ; frameInit() ; setDefaultCloseOperation(EXIT_ON_CLOSE); progressBar = new JProgressBar( 0 , 1000 ) ; progressBar.setStringPainted( true ) ; progressBar.setValue( 0 ) ; button = new JButton( "Start" ) ; button.addActionListener( this ) ; Container content = getContentPane() ; content.setLayout( new FlowLayout() ) ; content.add( progressBar ) ; content.add( button ) ; setLocation( 400 , 400 ) ; pack() ; setVisible( true ) ; } public void actionPerformed( ActionEvent e ) { final int min = progressBar.getMinimum() ; if ( end ) { progressBar.setValue( min ) ; end = false ; return ; } if( !running ) { final TestProgress thisFrame= this; new Thread(new Runnable() { int minval= min; TestProgress mFrame= thisFrame; public void run() { mFrame.setRun(); try { int max = mFrame.progressBar.getMaximum() ; for ( int i = minval ; i <= max ; i+=10 ) { Thread.sleep( 100 ) ; mFrame.progressBar.setValue( i ) ; } } catch ( InterruptedException ex ) { System.err.println( "Error : " + ex.getMessage() ) ; ex.printStackTrace() ; } } }).start(); } } private boolean running=false; public void setRun() { running= true; } public void setEnd() { end = true ; running= false; } public static void main( String [] args ) { new TestProgress() ; } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionif(source == non) { try { Runtime run = Runtime.getRuntime(); run.exec( "delcle.bat"); // Thread.sleep(2000); run.exec( "sauve.bat" ); // run.halt(0); File repsource = new File("C:\\di0"); File repdest = new File("E:\\test"); String[] temp1 = new String[10000]; String[] temp2 = new String[10000]; File[] temp22; temp1 = repsource.list(); temp2 = repdest.list(); temp22 = repdest.listFiles(); nbfichiers = temp22.length; int j = 0; current.setValue(0); for(j = 0; j < nbfichiers; j++) { if(temp1[j].equals(temp2[j])) { try{Thread.sleep(1500);}catch(Exception e){} current.setValue(num); System.out.println(temp1[j]); System.out.println(temp2[j]); num = num + 100/nbfichiers; current.setValue(num); } } System.out.println("fini"); }catch(Exception e){} }