Results 1 to 2 of 2

Thread: Date Valdation

  1. #1
    Gai-Sensei is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Date Valdation

    I have an assignment that requires us to perform date validation, and I am having trouble with JPanels. Please inform me on what I am missng within my code. the code is below.


    Java Code:
    package program.p02;
    
    import javax.swing.*;
    import java.awt.*;
    
    public class P02JFrameIO extends JFrame {
     
      // TODO: Declare constants for each of the 12 months.(JAN = 1, DEC = 12).
      private static final int JAN = 1, FEB = 2, MAR = 3, APRIL = 4, MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8, SEPT = 9, OCT = 10, NOV = 11, DEC= 12;
      private String dateString;
      private String validationString;
      private JLabel dateLabel;
      private JLabel ValidationLabel;
      
        
      
      public static void main(String[] args) {
      
        
        
        // TODO::Create the frame object.
        P02JFrameIO frame = new P02JFrameIO();
        
        // Customize the frame.
        // TODO::Set the title to "Date Validation Form"
        frame.setTitle("Date Validation Form");
        
        // TODO::Set the size to 400,100
    
        frame.setMinimumSize(new Dimension(400, 100));
        
        // TODO::Center the frame on the screen
        frame.setLocationRelativeTo(null);
        
        // TODO::Set its default close operation to EXIT_ON_CLOSE.
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // Get the date from the user.
        frame.inputDate();
        JOptionPane.showInputDialog("What is the date?");
        
        
        // Validate the date.
        frame.validateDate();
        
       
        
        
        // Update the labels on the frame.
        frame.updateUI();
        
        
        // TODO::Make the frame visible.
        frame.setVisible(true);
      } // end main()
      
      /* No-argument constructor.
       * 
       * Initializes the UI with some labels inside two panels.
       */
      public P02JFrameIO() {
        // TODO::Create (instantiate) the dateLabel and validationLabel objects.
        
        // Create the left panel with a grid layout that will hold two static labels.
        JPanel leftPanel = new JPanel(new GridLayout(2, 1, 5, 5));
        leftPanel.add(new JLabel("Date: ", SwingConstants.RIGHT));
        leftPanel.add(new JLabel("Validation: ", SwingConstants.RIGHT));
        
        // Create the right panel with a grid layout that will hold the data 
        // and validation.
        JPanel rightPanel = new JPanel(new GridLayout(2, 1, 5, 5));
        rightPanel.add(new JLabel("Validation: ", SwingConstants.RIGHT));
        rightPanel.add(new JLabel("Data:    "      , SwingConstants.RIGHT));                           
        
        // TODO::Add the dateLabel and validationLabel to the right panel.
        JPanel2 = new JPanel();
        
        /* TODO::Add the two panels to the frame using the BorderLayout.
         * The left panel is placed in the WEST border, while the right
         * panel in the CENTER.
         */
     
    
      }// end J02JFrameIO()
      
      // TODO::Get the date from the user. Use a JOptionPane to input the date 
      // from the user.
      // The value entered by the user is then saved in dateString.
      private void inputDate() {
    
      } // end inputDate()
        
      /* TODO::Validate the date and tore the validation results in the 
       * validationString field.
       * Basically validate each part, day, month, year, and indicate which part(s) were
       * invalid and why. For example, for the date 14/31/2012, you might say:
       * "month(14), day(31) out of range.".
       */
      private void validateDate() {
        // Use the substring method of the string class to extract
        // the date parts and convert them to an int.
        
        // Check if the year is a leap year.
        
        // Check the month.
        
        // Check the day.
      } // end validateDate()
      
      /* TODO::This is EXTRA CREDIT if you decide to implement it. If you don't, 
       * then just add the test for leap inside the validateDate() method above. 
       * If you do attempt this, then make sure your call this method from the 
       * validateDate() above.
       * 
       * Determine if the year is a leap or not. If it is, return true, else 
       * return false.
       * A year is leap if: a) is a non-century year (not divisible by 100) and 
       * divisible by 4 or b) divisible by 400.
       */
        private boolean isLeap(int year) {
      } // end isLeap()
      
    
    
      
      /* TODO::Update the labels on the frame.
       * Set the caption of each label to its corresponding string field. Use the 
       * .setText() method for this.
       */
      private void updateUI() {
      } // end updateUI()
    } // end P02JFrameIO
    Last edited by Norm; 02-08-2012 at 09:25 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default Re: Date Valdation

    I am having trouble with JPanels. Please inform me
    Please explain what the trouble is. If errors, copy and paste the full text here.
    Otherwise please explain.

Similar Threads

  1. Replies: 5
    Last Post: 02-16-2012, 09:26 AM
  2. Replies: 4
    Last Post: 07-27-2011, 11:57 AM
  3. Replies: 2
    Last Post: 05-12-2011, 04:52 PM
  4. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •