924 Files and Streams Chapter 16 124 fileChooser.setFileSelectionMode( (Web design service)
924 Files and Streams Chapter 16 124 fileChooser.setFileSelectionMode( 125 JFileChooser.FILES_ONLY ); 126 127 int result = fileChooser.showOpenDialog( this ); 128 129 // if user clicked Cancel button on dialog, return 130 if ( result == JFileChooser.CANCEL_OPTION ) 131 return; 132 133 // obtain selected file 134 fileName = fileChooser.getSelectedFile(); 135 } 136 137 // display error if file name invalid 138 if ( fileName == null || 139 fileName.getName().equals( “” ) ) 140 JOptionPane.showMessageDialog( this, 141 “Invalid File Name”, “Invalid File Name”, 142 JOptionPane.ERROR_MESSAGE ); 143 144 else { 145 146 // open file 147 try { 148 149 // close file from previous operation 150 if ( input != null ) 151 input.close(); 152 153 fileInput = new FileInputStream( fileName ); 154 input = new ObjectInputStream( fileInput ); 155 openButton.setEnabled( false ); 156 creditButton.setEnabled( true ); 157 debitButton.setEnabled( true ); 158 zeroButton.setEnabled( true ); 159 } 160 161 // catch problems manipulating file 162 catch ( IOException ioException ) { 163 JOptionPane.showMessageDialog( this, 164 “File does not exist”, “Invalid File Name”, 165 JOptionPane.ERROR_MESSAGE ); 166 } 167 } 168 169 } // end method openFile 170 171 // close file before application terminates 172 private void closeFile() 173 { 174 // close file 175 try { 176 input.close(); Fig. 16.9Credit inquiry program (part 4 of 7). Fig. 16.9
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.