Chapter 20 Java Utilities Package and Bit Manipulation (Web design tools)
Chapter 20 Java Utilities Package and Bit Manipulation 1163 27 displayArea.setEditable( false ); 28 29 JPanel northSubPanel = new JPanel(); 30 31 northSubPanel.add( new JLabel( “First name” ) ); 32 firstNameField = new JTextField( 8 ); 33 northSubPanel.add( firstNameField ); 34 35 northSubPanel.add( new JLabel( “Last name (key)” ) ); 36 lastNameField = new JTextField( 8 ); 37 northSubPanel.add( lastNameField ); 38 39 JPanel northPanel = new JPanel(); 40 northPanel.setLayout( new BorderLayout() ); 41 northPanel.add( northSubPanel, BorderLayout.NORTH ); 42 northPanel.add( statusLabel, BorderLayout.SOUTH ); 43 44 JPanel southPanel = new JPanel(); 45 southPanel.setLayout( new GridLayout( 2, 5 ) ); 46 JButton putButton = new JButton( “Put” ); 47 48 putButton.addActionListener( 49 50 new ActionListener() { 51 52 // add new key/value pair to hash table 53 public void actionPerformed( ActionEvent event ) 54 { 55 Employee employee = new Employee( 56 firstNameField.getText(), 57 lastNameField.getText() ); 58 59 Object value = 60 table.put( lastNameField.getText(), employee ); 61 62 // first time this key was added 63 if ( value == null ) 64 statusLabel.setText( 65 “Put: ” + employee.toString() ); 66 67 // replaced previous value for this key 68 else 69 statusLabel.setText( 70 “Put: ” + employee.toString() + 71 “; Replaced: ” + value.toString() ); 72 } 73 } 74 ); 75 76 southPanel.add( putButton ); 77 78 // button to get value for specific key 79 JButton getButton = new JButton( “Get” ); Fig. 20.3 Demonstrating class Hashtable(part 2 of 6).
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services