/** * @version 1.00 1999-07-17 * @author Cay Horstmann */importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.*;importjavax.swing.event.*;publicclassProgressBarTest{publicstaticvoidmain(String[]args){JFrameframe=newProgressBarFrame();frame.show();}}classProgressBarFrameextendsJFrame{publicProgressBarFrame(){setTitle("ProgressBarTest");setSize(300,200);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});ContainercontentPane=getContentPane();// this text area holds the activity outputtextArea=newJTextArea();// set up panel with button and progress barJPanelpanel=newJPanel();startButton=newJButton("Start");progressBar=newJProgressBar();progressBar.setStringPainted(true);panel.add(startButton);panel.add(progressBar);contentPane.add(newJScrollPane(textArea),"Center");contentPane.add(panel,"South");// set up the button actionstartButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){progressBar.setMaximum(1000);activity=newSimulatedActivity(1000);activity.start();activityMonitor.start();startButton.setEnabled(false);}});// set up the timer actionactivityMonitor=newjavax.swing.Timer(500,newActionListener(){publicvoidactionPerformed(ActionEventevent){intcurrent=activity.getCurrent();// show progresstextArea.append(current+"\n");progressBar.setValue(current);// check if task is completedif(current==activity.getTarget()){activityMonitor.stop();startButton.setEnabled(true);}}});}privatejavax.swing.TimeractivityMonitor;privateJButtonstartButton;privateJProgressBarprogressBar;privateJTextAreatextArea;privateSimulatedActivityactivity;}classSimulatedActivityextendsThread{publicSimulatedActivity(intt){current=0;target=t;}publicintgetTarget(){returntarget;}publicintgetCurrent(){returncurrent;}publicvoidrun(){while(current<target&&!interrupted()){try{sleep(100);}catch(InterruptedExceptione){return;}current++;}}privateintcurrent;privateinttarget;}
C
cabuloso8
Com esse exemplo dá pra adaptar do jeito que quiser , gostei, to criando um software aqui e adaptei nele. Fico massa.