/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import javax.swing.*; 

2. import java.awt.*; 

3. import java.awt.event.*; 

4.  

5. public class Progress 

6.     extends JApplet 

7.       implements ActionListener 

8.

9.   JProgressBar probar ; 

10.   Timer timer; 

11.   final int MAX = 100

12.  

13.   Container  cp ; 

14.   JButton bt = new JButton("Start"); 

15.  

16.   public Progress() 

17.   { 

18.     probar = new JProgressBar 

19.     ( JProgressBar.HORIZONTAL, 0, MAX ); 

20.  

21.     probar.setString( "0%" ); 

22.     probar.setStringPainted( true ); 

23.  

24.     timer = new Timer( 25, this ); 

25.  

26.     cp = getContentPane(); 

27.     cp.setLayout ( new FlowLayout()  ); 

28.     cp.add ( probar ) ; 

29.     cp.add ( bt ); 

30.     bt.addActionListener(this); 

31.   } 

32.  

33.   public void actionPerformed ( ActionEvent ev ) 

34.   { 

35.     if ( ev.getSource()== bt ) 

36.     { 

37.       timer.start( ); 

38.       bt.setEnabled(false); 

39.       return

40.     } 

41.     int val = probar.getValue(); 

42.     if ( val==100

43.     {   timer.stop();   return ;   } 

44.     val++; 

45.     probar.setString (  val + "%" ) ; 

46.  

47.     probar.setValue ( val ); 

48.   } 

49.

50.