Use timer, progressbar, and two buttons to create the applet. Click start to Unmount and stop.
The Code is as follows:
----------------------------------------------- The following is the code area --------------------------------------------------------------------------
Import Java. AWT. borderlayout; import Java. AWT. dimension; import Java. AWT. event. actionevent; import Java. AWT. event. actionlistener; import javax. swing. jbutton; import javax. swing. jframe; import javax. swing. jlabel; import javax. swing. jpanel; import javax. swing. jprogressbar; import javax. swing. timer; import javax. swing. event. changeevent; import javax. swing. event. changelistener; public class progressbar extends jframe implements changelistener, actionlistener {jbutton start, stop; jprogressbar bar; jlabel show; jpanel pane, pane1; timer; Public progressbar (String title) {super (title); Init (); Pack ();} public void Init () {setbounds (300,100,300,100); pane = new jpanel (); pane. setlayout (New borderlayout (); getcontentpane (). add (PANE); Start = new jbutton ("START"); start. addactionlistener (this); stop = new jbutton ("stop"); stop. addactionlistener (this); pane1 = new jpanel (); pane1.add (start); pane1.add (STOP); bar = new jprogressbar (); Bar. setminimum (0); Bar. setmaximum (100); Bar. setvalue (100); Bar. setstringpainted (true); Bar. addchangelistener (this); Bar. setpreferredsize (new dimension (200, 30); int leave = 100-bar. getvalue (); show = new jlabel ("completed:" + leave, jlabel. center); pane. add (pane1, borderlayout. north); pane. add (Bar, borderlayout. center); pane. add (show, borderlayout. south); timer = new timer (50, this) ;}@ overridepublic void statechanged (changeevent e) {// todo auto-generated method stubint value = bar. getvalue (); int leave = 100-value; If (E. getsource () = bar) {Show. settext ("completed:" + leave + "%") ;}@overridepublic void actionreceivmed (actionevent e) {// todo auto-generated method stubif (E. getsource () = Start) {timer. start ();} else if (E. getsource () = stop) {timer. stop (); Bar. setvalue (0);} else if (E. getsource () = timer) {int value = bar. getvalue (); If (value> 0) {value --; Bar. setvalue (value) ;}} public static void main (string [] ARGs) {New progressbar ("Uninstall "). setvisible (true );}}
------------------------------------------------------ The above is the code area ------------------------------------------------------------------------------
The running effect is as follows:
--------- ------------
Note: This code can be directly copied to run