Java Reference
In-Depth Information
//(No next record.)
JOptionPane.showMessageDialog(this,
"Incomplete record!\n"
+ "End of fi le reached.");
}
catch(IOException ioEx)
{
JOptionPane.showMessageDialog(this,
"Unable to read fi le!");
}
}
}
public void openFile() throws IOException
{
if (input != null) //A fi le is already open, so
//needs to be closed fi rst.
{
input.close();
input = null;
}
JFileChooser fi leChooser = new JFileChooser();
fi leChooser.setFileSelectionMode(
JFileChooser.FILES_ONLY);
int selection = fi leChooser.showOpenDialog(null);
//Window opened in centre of screen.
if (selection == JFileChooser.CANCEL_OPTION)
return;
File results = fi leChooser.getSelectedFile();
if (results ==
null||results.getName().equals(""))
//No fi le name entered by user.
{
JOptionPane.showMessageDialog(this,
"Invalid selection!");
return;
}
input = new Scanner(results);
readRecord(); //Read and display fi rst record.
nextButton.setEnabled(true); //(File now open.)
}
public void readRecord() throws IOException
{
String surname, fi rstNames, textMark;
Search WWH ::




Custom Search