1172 Java Utilities Package and (Adelphia web hosting) Bit Manipulation Chapter
1172 Java Utilities Package and Bit Manipulation Chapter 20 166 // button to load contents of Properties table from file 167 JButton loadButton = new JButton( “Load” ); 168 169 loadButton.addActionListener( 170 171 new ActionListener() { 172 173 // use method load to read contents from file 174 public void actionPerformed( ActionEvent event ) 175 { 176 // load contents of table 177 try { 178 FileInputStream input = 179 new FileInputStream( “props.dat” ); 180 181 table.load( input ); 182 input.close(); 183 listProperties(); 184 } 185 186 // process problems with file input 187 catch( IOException ioException ) { 188 ioException.printStackTrace(); 189 } 190 } 191 } 192 ); // end call to addActionListener 193 194 southPanel.add( loadButton ); 195 196 container.add( southPanel, BorderLayout.SOUTH ); 197 198 setSize( 550, 225 ); 199 setVisible( true ); 200 } 201 202 // output property values 203 public void listProperties() 204 { 205 StringBuffer buffer = new StringBuffer(); 206 String name, value; 207 208 Enumeration enumeration = table.propertyNames(); 209 210 while ( enumeration.hasMoreElements() ) { 211 name = enumeration.nextElement().toString(); 212 value = table.getProperty( name ); 213 214 buffer.append( name ).append( ‘t’ ); 215 buffer.append( value ).append( ‘n’ ); 216 } 217 218 displayArea.setText( buffer.toString() ); Fig. 20.4 Demonstrating class Properties(part 5 of 6).
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services