Page 623 - Introduction to Programming with Java: A Problem Solving Approach
P. 623
14.13 GUI Track and Problem Solving: Line Plot Example Revisited (Optional) 589
//*************************************************************
// This method prompts the user for an integer, performs input
// validation, and returns the entered integer.
private static int getIntFromUser(String prompt)
{
String entry;
// user entry
boolean valid = false; // is user entry a valid integer?
int entryInt = 0;
// integer form of user entry
entry = JOptionPane.showInputDialog(prompt);
do
{
try
{
entryInt = Integer.parseInt(entry);
valid = true;
helper method
}
// end class LinePlotGUI
}
// end getIntFromUser
}
while (!valid);
}
catch (NumberFormatException e)
{
}
entry = JOptionPane.showInputDialog(
Apago PDF Enhancer
"Invalid entry. Enter an integer:");
return entryInt;
//*************************************************************
public static void main(String[] args)
{
}
LinePlotGUI linePlotGUI = new LinePlotGUI();
linePlotGUI.readYCoordinates();
LinePlotPanel linePlotPanel = new LinePlotPanel(linePlotGUI);
linePlotGUI.add(linePlotPanel);
linePlotGUI.setVisible(true);
// end main
Figure 14.20c
LinePlotGUI class—part C