Advertisement
jbonanno

exception.java

Jun 18th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package vacationprice;
  6.  import java.io.IOException;
  7. import java.lang.Throwable;
  8. import javax.swing.*;
  9. import javax.swing.text.JTextComponent;
  10. import java.util.Scanner;
  11. /**
  12.  *
  13.  * @author j
  14.  */
  15. public class exception {
  16.  
  17. public static boolean isPresent(JTextComponent c, String title)
  18. {
  19.     if (c.getText().length() == 0)
  20.     {
  21.         showMessage(c, title + "is a required field.\n"
  22.                 + " Please re-enter.");
  23.         c.requestFocusInWindow();
  24.         return false;
  25.        
  26.     }
  27.     return true;
  28. }
  29.  
  30.  
  31. public static boolean isInteger(JTextComponent c, String title)
  32. {
  33.     try
  34.     {
  35.         int i = Integer.parseInt(c.getText());
  36.         return true;
  37. }
  38.  
  39.     catch (NumberFormatException e)
  40.     {
  41.          showMessage(c, title + "Should be an integer.\n"
  42.                 + " Please re-enter.");
  43.         c.requestFocusInWindow();
  44.         return false;
  45.     }
  46. }
  47.    
  48.    private static void showMessage(JTextComponent c, String message)
  49.     {
  50.         JOptionPane.showMessageDialog(c, message, "Invalid entry",
  51.               JOptionPane.ERROR_MESSAGE);
  52.     }
  53.    
  54.    
  55.    
  56.    
  57.  
  58.    
  59.    
  60.    
  61.    
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement