import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.lang.*;
public class DateApplication extends JFrame
{
private JButton birthdayButton,zodiacButton,chineseButton;
private JTextField monthField, dayField, yearField;
private JLabel inputPrompt;
private JPanel panel;
public static void main()
{
DateApplication frame = new DateApplication();
frame.setSize(350,300);
frame.createGUI();
frame.setTitle("Fun with Dates");
frame.setVisible(true);
}
private void createGUI()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout());
panel = new JPanel();
panel.setPreferredSize(new Dimension(300,200));
panel.setBackground(Color.white);
birthdayButton = new JButton("Check Birthday");
birthdayButton.addActionListener(new BirthdayDrawAction());
zodiacButton = new JButton("Zodiac");
zodiacButton.addActionListener(new ZodiacDrawAction());
chineseButton = new JButton("Chinese Year");
chineseButton.addActionListener(new ChineseDrawAction());
inputPrompt = new JLabel("Enter your bithday mm-dd-yyyy: ");
monthField = new JTextField(2);
dayField = new JTextField(2);
yearField = new JTextField(4);
window.add(inputPrompt);
window.add(monthField);
window.add(dayField);
window.add(yearField);
window.add(birthdayButton);
window.add(zodiacButton);
window.add(chineseButton);
window.add(panel);
}
private class BirthdayDrawAction implements ActionListener {
public void actionPerformed(ActionEvent event)
{
int month, day, year;
String inputMonth = monthField.getText();
month = Integer.parseInt(inputMonth);
String inputDay = dayField.getText();
day = Integer.parseInt(inputDay);
String inputYear = yearField.getText();
year = Integer.parseInt(inputYear);
Date theDate = new Date(month,day,year);
Graphics g = panel.getGraphics();
g.setColor(Color.white);
g.fillRect(0,0,300,200);
g.setColor(Color.red);
Font myFont = new Font("SansSerif", Font.BOLD, 24);
g.setFont(myFont);
// if (theDate.isBirthday()) {
// g.drawString("Happy Birthday",20,100);
// }
// else {
g.drawString("It's not your Birthday",20,100);
// }
}
}
private class ZodiacDrawAction implements ActionListener {
public void actionPerformed(ActionEvent event)
{
int month, day, year;
String inputMonth = monthField.getText();
month = Integer.parseInt(inputMonth);
String inputDay = dayField.getText();
day = Integer.parseInt(inputDay);
String inputYear = yearField.getText();
year = Integer.parseInt(inputYear);
Graphics g = panel.getGraphics();
panel.removeAll();
Date theDate = new Date(month,day,year);
Icon zodiacIcon = null;
// zodiacIcon = theDate.getZodiacSign();
JLabel label = new JLabel(zodiacIcon);
panel.add(label);
panel.revalidate();
panel.repaint();
}
}
private class ChineseDrawAction implements ActionListener {
public void actionPerformed(ActionEvent event)
{
int month, day, year;
String inputMonth = monthField.getText();
month = Integer.parseInt(inputMonth);
String inputDay = dayField.getText();
day = Integer.parseInt(inputDay);
String inputYear = yearField.getText();
year = Integer.parseInt(inputYear);
Icon ChineseIcon = null;
Graphics g = panel.getGraphics();
panel.removeAll();
Date theDate = new Date(month,day,year);
Icon chineseIcon = null;
// chineseIcon = theDate.getChineseYear();
JLabel label = new JLabel(chineseIcon);
panel.add(label);
panel.revalidate();
panel.repaint();
}
}
/**
private class Date //(int month, int day, int year)
{
// int month, day, year, currentMonth, currentDay, currentYear;
// String currentMonthString, currentDayString, currentYearString, theDate;
Calendar todaysDate = Calendar.getInstance();
SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
String currentMonthString = monthFormat.format(todaysDate.getTime());
int currentMonth = Integer.parseInt(currentMonthString);
SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
String currentDayString = dayFormat.format(todaysDate.getTime());
int currentDay = Integer.parseInt(currentDayString);
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
String currentYearString = yearFormat.format(todaysDate.getTime());
int currentYear = Integer.parseInt(currentYearString);
String theDate = currentMonthString + currentDayString + currentYearString;
public boolean inBirthday (int month, int day, int year)
{
if (month == currentMonth && day == currentDay)
{
return true;
}
else return false;
}
public Icon getZodiacSign (int month, int day)
{
if ((month == 1 && day >= 20) || (month == 2 && day <= 18))
{
ImageIcon zodaicIcon = new ImageIcon("Aquarius.jpg");
}
if ((month == 2 && day >= 19) || (month == 3 && day <= 20))
{
ImageIcon zodaicIcon = new ImageIcon("Pisces.jpg");
}
if ((month == 3 && day >= 21) || (month == 4 && day <= 19))
{
ImageIcon zodaicIcon = new ImageIcon("Aries.jpg");
}
if ((month == 4 && day >= 20) || (month == 5 && day <= 20))
{
ImageIcon zodaicIcon = new ImageIcon("Taurus.jpg");
}
if ((month == 5 && day >= 21) || (month == 6 && day <= 20))
{
ImageIcon zodaicIcon = new ImageIcon("Gemini.jpg");
}
if ((month == 6 && day >= 21) || (month == 7 && day <= 22))
{
ImageIcon zodaicIcon = new ImageIcon("Cancer.jpg");
}
if ((month == 7 && day >= 23) || (month == 8 && day <= 22))
{
ImageIcon zodaicIcon = new ImageIcon("Leo.jpg");
}
if ((month == 8 && day >= 23) || (month == 9 && day <= 22))
{
ImageIcon zodaicIcon = new ImageIcon("Virgo.jpg");
}
if ((month == 9 && day >= 23) || (month == 10 && day <= 22))
{
ImageIcon zodaicIcon = new ImageIcon("Libra.jpg");
}
if ((month == 10 && day >= 23) || (month == 11 && day <= 21))
{
ImageIcon zodaicIcon = new ImageIcon("Scorpio.jpg");
}
if ((month == 11 && day >= 22) || (month == 12 && day <= 21))
{
ImageIcon zodaicIcon = new ImageIcon("Sagittarius.jpg");
}
if ((month == 12 && day >= 22) || (month == 1 && day <= 19))
{
ImageIcon zodaicIcon = new ImageIcon("Capricorn.jpg");
}
return zodiacIcon;
}
}
*/
}