Java Reference
In-Depth Information
//Clear text fi elds…
surnameBox.setText("");
fi rstNamesBox.setText("");
markBox.setText("");
if (input.hasNext()) //Not at end of fi le.
{
surname = input.nextLine();
surnameBox.setText(surname);
}
else
{
JOptionPane.showMessageDialog(this,
"End of fi le reached.");
nextButton.setEnabled(false);//No next record.
return;
}
//Should cater for possibility of incomplete
//records…
if (!input.hasNext())
throw (new EOFException());
//Otherwise…
fi rstNames = input.nextLine();
fi rstNamesBox.setText(fi rstNames);
if (!input.hasNext())
throw (new EOFException());
//Otherwise…
textMark = input.nextLine();
markBox.setText(textMark);
}
}
Note that neither windowClosing nor actionPerformed can throw an exception,
since their signatures do not contain any throws clause and we cannot change those
signatures. Consequently, any exceptions that do arise must be handled explicitly
either by these methods themselves or by methods called by them (as with method
closeFile ).
4.8
ArrayLists
An object of class ArrayList is like an array, but can dynamically increase or
decrease in size according to an application's changing storage requirements
and can hold only references to objects, not values of primitive types. As of Java
Search WWH ::




Custom Search