I'm working on a calender program for school... Task: Create an Applet with three fields (dd,mm,yyyy) and a get birthday button... The Applet will then display(through an algorithm of strings and loops) the correct month, year, and date with the birthday highlighted... And dates must be off set correctly... For example... DEC 14 the 1st must fall underneath the W column... PROGRAM RUNS PERFECT! Except... I can't get the invalid input to return correctly... For example, If I put month 13, I get invalid month input: 13(which is good) but If I put 14+ I get nothing... Same thing with days past 31... Heres what the error check looks like and I have the days and months in an array...
//HW 10 BirthdayApplet
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
//Applet..
public class BirthdayApplet extends Applet implements ActionListener {
//Constants...
private static final int FIRST_DAY = 3;
//Instance Variables...
private int inputDay, inputMonth, inputYear;
private boolean displayCalendar = false; // flag to display calendar
private int firstDayofInputMonth = 0;
//Array of days in int...
private int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31};
//Array of months in string...
private String monthNames[] = {"", "January", "February", "March",
"April", "May", "June", "July", "August", "September", "October",
"November", "December"};
//Labels...
private Label monthLabel;
private Label dayLabel;
private Label yearLabel;
//TextFields...
private TextField monthField;
private TextField dayField;
private TextField yearField;
//Button...
private Button displayButton;
//Init...
public void init(){
//Creation of Labels...
monthLabel = new Label("Month (mm):");
dayLabel = new Label("Day (dd):");
yearLabel = new Label("Year (yyyy):");
//Creation of Fields...
monthField = new TextField (10);
dayField = new TextField (10);
yearField = new TextField (10);
//Creations of Button...
displayButton = new Button("Display Birthday");
displayButton.addActionListener(this);
//Addition of all created to applet...
add(monthLabel);
add(monthField);
add(dayLabel);
add(dayField);
add(yearLabel);
add(yearField);
add(displayButton);
//Set window size...
setSize(1000,1000);
}
//Action...
public void actionPerformed (ActionEvent e){
if (e.getSource() == displayButton){
displayCalendar = true;
//Convert input strings to int...
inputMonth = Integer.parseInt(monthField.getText());
inputDay = Integer.parseInt(dayField.getText());
inputYear = Integer.parseInt(yearField.getText());
//First day of month getter...
firstDayofInputMonth = getDayOfWeek(getDay(inputMonth, 1));
}
repaint();//Repaint on new action...
}
//Paint...
public void paint (Graphics g){
Font Default = new Font("TimesRoman", Font.ROMAN_BASELINE, 20);//Set Font....
Font BOLD = new Font("TimesRoman", Font.BOLD, 23);
g.setFont(Default);
int xCoord = 450;
int yCoord = 100;
int Counter=0;//Value traversing through loop....
if (displayCalendar == true){
//Month/Day Validation...
if(inputMonth>12 || inputMonth<1)
g.drawString("INVALID Month input: "+inputMonth , 520, 75);
else if(inputDay>31|| inputDay<1)
g.drawString("INVALID Day input: "+inputDay , 520, 100);
//If good data...
else{
Help?