Alright I've gotten everything working except for the actual print out of the dates in the month. I'll post the full code again, as I have it completed thus far. Any pointers are GREATLY appreciated.
import java.applet.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class BirthdayApplet extends Applet implements ActionListener
{
public static int WIDTH=500, HEIGHT=500;
private Button displayButton;
private TextField monthField, dayField, yearField;
private AudioClip myAudioClip;
private int inputMonth, inputDay, inputYear = 1, dayPrinter = 1;
private int firstDayofYear = 2, firstDayOfMonth = -1, firstDayofWeek = 2;
private String year = "", days = "";
// Creates arrays to store the days in the month and their names.
int[] daysINmonth = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
String[] monthNames = {" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int[] daysINweek = {0, 1, 2, 3, 4, 5, 6};
String[] daysOFweek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Initializes the applet
public void init()
{
setSize (WIDTH, HEIGHT);
// Plays 'Happy Birthday' Song
myAudioClip = getAudioClip(getCodeBase(), "../../audio.mid");
myAudioClip.loop();
// Creates the textfields, labels, and buttons.
displayButton = new Button ("Display Birthday");
displayButton.addActionListener(this);
monthField = new TextField (2);
dayField = new TextField (2);
yearField = new TextField (4);
Label monthLabel = new Label ("Month");
Label dayLabel = new Label (" Day");
Label yearLabel = new Label (" Year");
// Adds the buttons, labels, and textfields to applet.
add(monthLabel);
add(monthField);
add(dayLabel);
add(dayField);
add(yearLabel);
add(yearField);
add(displayButton);
}
// Determines if the input year is a leap year.
private static boolean isLeapYear(int year)
{
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
{
return true;
}
else
{
return false;
}
}
// Finds the Julian Day equivalency of inputs.
private int getDay(int month, int year)
{
int jday = 0;
for (int i = 1; i < inputMonth; i++)
{
jday = jday + daysINmonth[i];
}
jday = jday + inputDay;
return jday;
}
// Finds which day of the week birthday falls.
private int getDayOfWeek(int jday)
{
return (jday + firstDayofWeek - 1)%7;
}
// Paints calendar and leap year (if applicable).
public void paint (Graphics g)
{
if (isLeapYear(inputYear) == true)
{
g.drawString("The year you were born was a leap year!", 140, 300);
}
if (inputMonth > 3 && inputMonth < 8)
{
g.drawString(" " + monthNames[inputMonth] + " " + year, 205, 100);
}
else
g.drawString(monthNames[inputMonth] + " " + year, 205, 100);
g.drawString(days, 170, 125);
for (int weeks = 1; weeks < 7; weeks++)
{
for (int day = 0; day < 7; day++)
{
if (weeks == 1 && day < firstDayOfMonth)
{
g.drawString(" ", 170, 150);
}
else
{
if (dayPrinter < 31)
{
String dayPrinter2 = String.valueOf(dayPrinter);
g.drawString(" " + dayPrinter2 + " ", 170, 150);
dayPrinter = Integer.parseInt(dayPrinter2.trim());
dayPrinter++;
}
}
}
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == displayButton)
{
// Converts inputs from strings to integer values.
inputMonth = Integer.parseInt(monthField.getText());
inputDay = Integer.parseInt(dayField.getText());
inputYear = Integer.parseInt(yearField.getText());
year = "2008";
days = "S " + "M " + "T " + "W " + "T " + "F " + "S";
repaint();
}
}
}