Freelance web design - Chapter 20 Java Utilities Package and Bit Manipulation
Chapter 20 Java Utilities Package and Bit Manipulation 1157 22 Container container = getContentPane(); 23 24 statusLabel = new JLabel(); 25 stack = new Stack(); 26 27 container.setLayout( new FlowLayout() ); 28 container.add( new JLabel( “Enter a string” ) ); 29 inputField = new JTextField( 10 ); 30 container.add( inputField ); 31 32 // button to place object on stack 33 JButton pushButton = new JButton( “Push” ); 34 35 pushButton.addActionListener( 36 37 new ActionListener() { 38 39 public void actionPerformed( ActionEvent event ) 40 { 41 // put object on Stack 42 statusLabel.setText( “Pushed: ” + 43 stack.push( inputField.getText() ) ); 44 } 45 } 46 ); 47 48 container.add( pushButton ); 49 50 // button to remove top object on stack 51 JButton popButton = new JButton( “Pop” ); 52 53 popButton.addActionListener( 54 55 new ActionListener() { 56 57 public void actionPerformed( ActionEvent event ) 58 { 59 // remove element from Stack 60 try { 61 statusLabel.setText( “Popped: ” + stack.pop() ); 62 } 63 64 // process exception if Stack empty 65 catch ( EmptyStackException exception ) { 66 statusLabel.setText( exception.toString() ); 67 } 68 } 69 } 70 ); 71 72 container.add( popButton ); 73 Fig. 20.2 Demonstrating class Stackof package java.util(part 2 of 5).
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services