Results 1 to 2 of 2
Thread: Date Validation
- 02-08-2012, 08:52 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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
-
Re: Date Validation
Please don't double post the same question. Locking.
Similar Threads
-
Taking user input as a date and validation!
By Junki3JJC in forum New To JavaReplies: 3Last Post: 03-29-2011, 01:28 PM -
date validation
By droidus in forum New To JavaReplies: 5Last Post: 03-19-2011, 01:37 PM -
License date validation
By thaneshkadi in forum Forum LobbyReplies: 0Last Post: 10-23-2009, 12:26 AM -
Date Validation Script
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:18 PM


LinkBack URL
About LinkBacks

Bookmarks