/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package vacationprice; import java.io.IOException; import java.lang.Throwable; import javax.swing.*; import javax.swing.text.JTextComponent; import java.util.Scanner; /** * * @author j */ public class exception { public static boolean isPresent(JTextComponent c, String title) { if (c.getText().length() == 0) { showMessage(c, title + "is a required field.\n" + " Please re-enter."); c.requestFocusInWindow(); return false; } return true; } public static boolean isInteger(JTextComponent c, String title) { try { int i = Integer.parseInt(c.getText()); return true; } catch (NumberFormatException e) { showMessage(c, title + "Should be an integer.\n" + " Please re-enter."); c.requestFocusInWindow(); return false; } } private static void showMessage(JTextComponent c, String message) { JOptionPane.showMessageDialog(c, message, "Invalid entry", JOptionPane.ERROR_MESSAGE); } }