1158 Java Utilities Package and Bit Manipulation Chapter (Web site translator)

1158 Java Utilities Package and Bit Manipulation Chapter 20 74 // button to look at top element of stack 75 JButton peekButton = new JButton( “Peek” ); 76 77 peekButton.addActionListener( 78 79 new ActionListener() { 80 81 public void actionPerformed( ActionEvent event ) 82 { 83 // look at top object on Stack 84 try { 85 statusLabel.setText( “Top: ” + stack.peek() ); 86 } 87 88 // process exception if Stack empty 89 catch ( EmptyStackException exception ) { 90 statusLabel.setText( exception.toString() ); 91 } 92 } 93 } 94 ); 95 96 container.add( peekButton ); 97 98 // button to determine whether stack is empty 99 JButton emptyButton = new JButton( “Is Empty?” ); 100 101 emptyButton.addActionListener( 102 103 new ActionListener() { 104 105 public void actionPerformed( ActionEvent event ) 106 { 107 // determine if Stack is empty 108 statusLabel.setText( stack.empty() ? 109 “Stack is empty” : “Stack is not empty” ); 110 } 111 } 112 ); 113 114 container.add( emptyButton ); 115 116 // button to determine whether search key is in stack 117 JButton searchButton = new JButton( “Search” ); 118 119 searchButton.addActionListener( 120 121 new ActionListener() { 122 123 public void actionPerformed( ActionEvent event ) 124 { 125 // search Stack for specified object 126 String searchKey = inputField.getText(); Fig. 20.2 Demonstrating class Stackof package java.util(part 3 of 5).
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Leave a Reply