AMADEUS html plain
import java . util . * ;
import java . awt . * ;
import java . awt . event . * ;
import javax . swing . * ;
import javax . swing . event . * ;
http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/node127.html
class StarterProgressBar
public class StarterProgressBar extends JFrame implements ActionListener
private JProgressBar progress ;
private JButton button ;
private JLabel label1 ;
private JPanel topPanel ;
private int updN;
public static String midaTeeme = "Amadeus_AlgJava loomine/värskendamine ";
StarterProgressBar
public
StarterProgressBar (int n)
updN = n;
setLocation(300, 400);
//setTitle ( "AlgJavaStarter " ) ;
setSize ( 610 , 90 ) ;
310
setBackground ( Color . gray ) ;
topPanel = new JPanel ( ) ;
topPanel.setLayout(new GridLayout(3, 1));
//topPanel . setPreferredSize ( new Dimension ( 810 , 130 ) ) ;
310
getContentPane ( ) . add ( topPanel ) ;
Create a label and progress bar
label1 = new JLabel ( "Waiting to start loading/updating Amadeus_AlgJava ..." ) ;
label1 . setPreferredSize ( new Dimension ( 380 , 24 ) ) ;
topPanel . add ( label1);//, BorderLayout.NORTH);
progress = new JProgressBar ( ) ;
progress . setPreferredSize ( new Dimension ( 300 , 20 ) ) ;
progress . setMinimum ( 0 ) ;
progress . setMaximum ( updN+1 ) ;
progress . setValue ( 0 ) ;
progress . setBounds ( 20 , 35 , 220 , 20 ) ;
progress.setLocation(new Point(20, 40));
topPanel . add ( progress);//, BorderLayout.CENTER) ;
button = new JButton ( "Start" ) ;
topPanel . add ( button);//, BorderLayout.EAST) ;
button . addActionListener ( this ) ;
void actionPerformed
public
void actionPerformed ( ActionEvent event )
..if
? event . getSource ( ) == button
Prevent more button presses
button . setEnabled ( false ) ;
Perform all of our tasks
..for
* int iCtr = -1 ; iCtr < updN ; iCtr ++
Do some sort of simulated task
AlgJavaStarter.teha( iCtr ) ;
Update the progress indicator and label
label1 . setText ( midaTeeme ) ;
Rectangle labelRect = label1 . getBounds ( ) ;
labelRect . x = 0 ;
labelRect . y = 0 ;
label1 . paintImmediately ( labelRect ) ;
progress . setValue ( iCtr+1 ) ;
Rectangle progressRect = progress . getBounds ( ) ;
progressRect . x = 0 ;
progressRect . y = 0 ;
progress . paintImmediately ( progressRect ) ;
Update the progress indicator and label
label1 . setText ( "Modifying properties ..." ) ;
Rectangle labelRect = label1 . getBounds ( ) ;
labelRect . x = 0 ;
labelRect . y = 0 ;
label1 . paintImmediately ( labelRect ) ;
progress . setValue ( updN ) ;
Rectangle progressRect = progress . getBounds ( ) ;
progressRect . x = 0 ;
progressRect . y = 0 ;
progress . paintImmediately ( progressRect ) ;
String tulem = AlgJavaStarter.modifyPropertiesAndStart();
//void DoBogusTask
public
void DoBogusTask ( int iCtr )
Random random = new Random ( iCtr ) ;
Waste some time
..for
* int iValue = 0 ; iValue < random . nextFloat ( ) * 10000 ; iValue ++
..for
* int jValue = 0 ; jValue < random . nextFloat ( ) * 10000 ; jValue ++
..for
* int kValue = 0 ; kValue < random . nextFloat ( ) * 10000 ; kValue ++
..for
* int kValu = 0 ; kValu < random . nextFloat ( ) * 10000 ; kValu ++
System . out . println ( "iValue=" + iValue ) ;
//void main
public static
void main ( String args [ ] )
Create an instance of the test application
StarterProgressBar mainFrame = new StarterProgressBar ( ) ;
mainFrame . setVisible ( true ) ;
mainFrame . pack ( ) ;