// // DayJob applet written by Richard Murphy (rick@shagtown.com). // // The DayJob class provides an applet interface to the date conversion functionality // in the WorldDate class. The VERSION parameter will determine the interface // to display, which is usually either input fields for month, day, and year // for one of several calendar systems, or it is just a year box. A text field // will then be updated with the relevant information, such as a Gregorian date. // If the version is "Everything", then the calendar system may also be selected, // and a large text box will display complete information about the date. import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.Vector; //import WorldDate; public class DayJob extends Applet implements ActionListener, ItemListener { WorldDate date; // Brains of the operation. int type; // Version of applet. Choice calendar; // Calendar system used. TextField gyear; // Gregorian year only. TextField year; // Year (any calendar). Choice month; // Month choices (any calendar). TextField day; // Number of day. Label label; // Output goes here. TextArea text; // Multi-line output goes here. Button debug; // Types. static final int EPACT = 0; static final int DOMLET = 1; static final int FRIDAY13 = 2; static final int CHINZOD = 3; static final int HEBREW = 4; static final int ISLAMIC = 5; static final int HINDU = 6; static final int JULIAN = 7; static final int EVERYTHING = 8; static final int LEAPYEAR = 9; static final int EASTER = 10; public void init() { date = new WorldDate(); // Set background color. int bgcolor = 0xeeeeee0; // Parchment color by default. String bgparam = getParameter("bgcolor"); if ((bgparam != null) && bgparam.equals("white")) { bgcolor = 0xffffff; } setBackground(new Color(bgcolor)); //setBackground(null); setLayout(new FlowLayout(FlowLayout.LEFT)); String version = getParameter("version"); // Set a constant which will indicate the information to be input // and what data will be displayed. if (version.equals("Epact")) // Age of new moon on Jan 1. type = EPACT; else if (version.equals("DominicalLetter")) // Weekday of Jan 1. type = DOMLET; else if (version.equals("Friday13")) // Dates of Fri 13. type = FRIDAY13; else if (version.equals("ChineseZodiac")) // Snake, Dragon, etc. type = CHINZOD; else if (version.equals("Hebrew")) // Jewish festivals. type = HEBREW; else if (version.equals("Islamic")) // Islamic calendar. type = ISLAMIC; else if (version.equals("Hindu")) // Hindu calendar. type = HINDU; else if (version.equals("JulianDay")) // Date in # of days. type = JULIAN; else if (version.equals("Everything")) // Full display. type = EVERYTHING; else if (version.equals("LeapYear")) // yes or no. type = LEAPYEAR; else if (version.equals("Easter")) // Date of Easter Sunday. type = EASTER; // The type will determine the input fields. switch (type) { case EPACT: case DOMLET: case FRIDAY13: case CHINZOD: case LEAPYEAR: case EASTER: // A single text box for entering the Gregorian year. gyear = new TextField(5); gyear.setText(String.valueOf(date.getYear())); gyear.addActionListener(this); add(gyear); label = new Label(); add(label); break; case HEBREW: case ISLAMIC: case HINDU: case JULIAN: // User selects the months from a pull-down menu and may // enter the day and year in text boxes. Month menu varies // for calendar system. Vector months; String defYear; switch (type) { case HEBREW: months = date.HebrewMonths; defYear = "5762"; break; case ISLAMIC: months = date.IslamicMonths; defYear = "1422"; break; case HINDU: months = date.HinduMonths; defYear = "1923"; break; case JULIAN: default: months = date.GregMonths; defYear = String.valueOf(date.getYear()); break; } month = new Choice(); setMonthChoice(month, months); month.addItemListener(this); add(month); day = new TextField(3); day.setText("1"); day.addActionListener(this); add(day); year = new TextField(5); year.setText(defYear); year.addActionListener(this); add(year); label = new Label(); add(label); date.setDate(year.getText(), month.getSelectedItem(), day.getText()); break; case EVERYTHING: // User selects calendar system from a pulldown menu then // may enter the date for that system by selecting month and // entering day and year. Information on the date is // displayed in a text box. Rectangle box; // Dimensions of components. setLayout(null); box = new Rectangle(5, 5, 90, 30); calendar = new Choice(); calendar.addItem("Gregorian"); calendar.addItem("Hebrew"); calendar.addItem("Islamic"); calendar.addItem("Hindu"); calendar.addItemListener(this); add(calendar); calendar.setBounds(box); box.translate(0, 35); // New row. month = new Choice(); setMonthChoice(month, date.GregMonths); month.addItemListener(this); add(month); month.setBounds(box); box.translate(95, 0); // Next column. box.setSize(40, 30); day = new TextField(3); day.setText("1"); day.addActionListener(this); add(day); day.setBounds(box); box.translate(45, 0); // Next column. box.setSize(50, 30); year = new TextField(5); year.setText(String.valueOf(date.getYear())); year.addActionListener(this); add(year); year.setBounds(box); box.translate(55, 0); // Next column. box.setSize(200, 30); label = new Label(); add(label); label.setBounds(box); box.setLocation(5, 70); // New row. box.setSize(300, 200); text = new TextArea(); text.setEditable(false); add(text); text.setBounds(box); date.setDate(year.getText(), month.getSelectedItem(), day.getText()); break; } // switch on type // Now display the info for the default date. display(); } // init() private void setMonthChoice(Choice c, Vector months) { for (int i = 0; i < months.size(); i++) c.addItem(months.elementAt(i).toString()); } public void actionPerformed(ActionEvent e) { // Determine what object was changed, then update the date and // redisplay the info. Object source = e.getSource(); if (source == gyear) { date.setYear(gyear.getText()); display(); } else if (source == month || source == day || source == year) { date.setDate(year.getText(), month.getSelectedItem(), day.getText()); display(); } } // actionPerformed() public void itemStateChanged(ItemEvent e) { Object source = e.getSource(); if (source == month) { date.setDate(year.getText(), month.getSelectedItem(), day.getText()); display(); } else if (source == calendar) { remove(month); month = new Choice(); String item = calendar.getSelectedItem(); day.setText("1"); if (item.equals("Gregorian")) { setMonthChoice(month, date.GregMonths); year.setText(String.valueOf(date.getYear())); } else if (item.equals("Hebrew")) { setMonthChoice(month, date.HebrewMonths); year.setText("5762"); } else if (item.equals("Islamic")) { setMonthChoice(month, date.IslamicMonths); year.setText("1422"); } else if (item.equals("Hindu")) { setMonthChoice(month, date.HinduMonths); year.setText("1923"); } month.setVisible(false); month.addItemListener(this); add(month); month.setBounds(5, 35, 90, 30); month.setVisible(true); date.setDate(year.getText(), month.getSelectedItem(), day.getText()); display(); } else if (source == debug) { remove(month); month = new Choice(); setMonthChoice(month, date.HebrewMonths); month.addItemListener(this); add(month); month.setSize(100, 10); } } // itemStateChanged() public void display() { // Usually the date info is a single piece of data that is displayed // in the label area. Blanks are appended to the new display to // ensure that the previous display gets overwritten. switch (type) { case EPACT: label.setText("Epact = " + String.valueOf(date.epact())); break; case DOMLET: label.setText("Dominical letter = " + date.dominicalLetter()); break; case FRIDAY13: label.setText("Friday the 13 is on " + Friday13() + " "); break; case CHINZOD: label.setText("Chinese zodiac = " + date.ChineseZodiac() + " "); break; case EASTER: date.Easter(); label.setText(date.toString() + " "); break; case HEBREW: case ISLAMIC: case HINDU: label.setText(date.toString() + " "); break; case JULIAN: label.setText("Julian Day = " + String.valueOf(date.toJulian()) + " "); break; case LEAPYEAR: label.setText("Leap year = " + date.leapYear() + " "); break; case EVERYTHING: // This type is displaying complete date information in // a text box, which must be cleared, then all the data // is appended to the box. label.setText(date.toString() + " "); text.setText(""); text.append("Date info...\n"); text.append("Weekday = " + date.weekdayStr() + "\n"); text.append("Julian Day = " + String.valueOf(date.toJulian()) + "\n"); text.append("\nYear info...\n"); text.append("Leap year = " + date.leapYearStr() + "\n"); text.append("Epact = " + String.valueOf(date.epact()) + "\n"); text.append("Dominical letter = " + date.dominicalLetter() + "\n"); text.append("Chinese zodiac = " + date.ChineseZodiac() + "\n"); break; } } // display() private String Friday13() { // WorldDate does not provide a function for Friday the 13th because // it is implied by the Dominical Letter (which indicates the day // of the week on Jan 1). There will be two Dominical Letters in // leap years: a new one for after Feb 29. String dm = date.dominicalLetter(); if (dm.equals("A")) return "Jan 13, Oct 13"; else if (dm.equals("AG")) return "Jan 13, Apr 13, Jul 13"; else if (dm.equals("B") || dm.equals("CB")) return "May 13"; else if (dm.equals("BA")) return "Oct 13"; else if (dm.equals("C")) return "Aug 13"; else if (dm.equals("D")) return "Feb 13, Mar 13, Nov 13"; else if (dm.equals("DC")) return "Feb 13, Aug 13"; else if (dm.equals("E") || dm.equals("FE")) return "Jun 13"; else if (dm.equals("ED")) return "Mar 13, Nov 13"; else if (dm.equals("F") || dm.equals("GF")) return "Sep 13, Dec 13"; else if (dm.equals("G")) return "Apr 13, Jul 13"; else return "error"; } // Friday13() } // DayJob