ceyesuma -4 Posting Pro

hello
I need a temp fix for putting times into my form. I suspect that soon I will have to
work with some kind of calender class that will send selected data in all the
correct formats. I have no clue. BUT right now it stop me in the first time
field because it is not checking hh:mm a. (please find time_pic attached)

However is there another constructor for the GregorianCalendar or a way to
use this constructor and Effectively validate HH:MM: Am Or Pm because now
it is checking to see if the day and month ect are correct.

package view.utils.formattedFields.verifiers;

import java.awt.Color;
import java.sql.Time;
import java.text.SimpleDateFormat;
import javax.swing.InputVerifier;
import view.utils.formattedFields.FormattedDateField;
import view.utils.formattedFields.FormattedTimeField;

/**
 *
 * @author Mark Pendergast
 * Copyright Mark Pendergast
 */
public class TimeVerifier extends InputVerifier {
  private static final Color INVALID_COLOR = Color.red;
  private static final Color VALID_COLOR = Color.black;
    
  SimpleDateFormat sdf = null; // formatted used to check date formats
  /**
   * Default constructor
   */
 public TimeVerifier()
 {
  sdf = new SimpleDateFormat();
 }
 /**
  * Constructor that accepts a mask
  * 
  * @param mask SimpleDateFormat mask
  */
         
 public TimeVerifier(String mask)
 {
   sdf = new SimpleDateFormat(mask);
 }
 /**
  * Check the contents to see if its a valid date
  * 
  * @param jc JComponent (the date field)
  * @return true if valid date, false if not
  */
 public boolean verify(javax.swing.JComponent jc)
 {
   FormattedTimeField fdf = (view.utils.formattedFields.FormattedTimeField)jc;
   try{
      Time d = (Time) sdf.parse(fdf.getText());  // note this allows months > 12, days > 31
      jc.setForeground(VALID_COLOR);
      return true;
   }
   catch(Exception e)
   {
    jc.setForeground(INVALID_COLOR);
    return false;
   }

 }

}

Please find the time_pic attached to view the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.