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.
:(think):
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
