Results 1 to 2 of 2

Thread: Date Validation

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

    Default Date Validation

    Having trouble with creating JPanels, and performing date validation.
    I need if else statements as well any help would be appreciated.


    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_CLOS E);

    // 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Taking user input as a date and validation!
    By Junki3JJC in forum New To Java
    Replies: 3
    Last Post: 03-29-2011, 01:28 PM
  2. date validation
    By droidus in forum New To Java
    Replies: 5
    Last Post: 03-19-2011, 01:37 PM
  3. License date validation
    By thaneshkadi in forum Forum Lobby
    Replies: 0
    Last Post: 10-23-2009, 12:26 AM
  4. Date Validation Script
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 08:18 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
  •