/** * Date Chooser Class * * Displays a small calendar for date selection * Created on April 28, 2005 * @author Jim Adams * */ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.GridLayout; //import java.awt.Image; //import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Point; //import java.text.DateFormat; //import java.text.SimpleDateFormat; import java.awt.*; import javax.swing.*; import java.lang.Object; import java.util.*; public class DateChooser { final int MAX=42; private JFrame frame = new JFrame(); private JPanel p0 = new JPanel(); // main panel private JPanel p1 = new JPanel(); // Date panel private JPanel p2 = new JPanel(); // Arrow panel private JPanel p3 = new JPanel(); // Cancel/Select Button Panel private GridLayout grid1 = new GridLayout(7,7,1,1); // day buttons private GridLayout grid2 = new GridLayout(1,2,2,2); // arrow buttons private GridLayout grid3 = new GridLayout(1,4,2,2); // cancel/select buttons private BorderLayout border0 = new BorderLayout(4,4); // main panel private Point location = new Point(); private JButton cancelbutton = new JButton("Cancel"); private JButton selectbutton = new JButton("Select"); private JDialog d = new JDialog(frame, null, true); private JButton[] daybutton = new JButton[MAX]; private JButton[] headbutt = new JButton[7]; private Font verdana8bold = new Font("Verdana", Font.BOLD, 8); private Font verdana9plain = new Font("Verdana", Font.PLAIN, 9); private Font verdana9bold = new Font("Verdana", Font.BOLD, 9); private Font verdana10plain = new Font("Verdana", Font.PLAIN, 10); private Font verdana10bold = new Font("Verdana", Font.BOLD, 10); private Font verdana11bold = new Font("Verdana", Font.BOLD, 11); private Font courier10bold = new Font("Courier New", Font.BOLD, 10); private Font courier10plain = new Font("Courier New", Font.PLAIN, 10); private Font courier11plain = new Font("Courier New", Font.PLAIN, 11); private Color red = new Color(255,0,0); private Color blue = new Color(0,0,255); private Color lightblue = new Color(144,144,255); private Color lightgrey = new Color(240,248,240); private Color white = new Color(255,255,255); private Color black = new Color(0,0,0); private String selected_month =""; private String selected_day =""; private String selected_year =""; /** Default Constructor @date 04/18/2005 @author Jim Adams @param None @return Nothing */ public DateChooser() { set_look_and_feel(); this.location.x = 400; this.location.y = 400; } // end of constructor /** Alternate Constructor @date 03/18/2005 @author Jim Adams @param Passed a Point Componet with x,y start location for the fram @return Nothing */ public DateChooser(Point p) { set_look_and_feel(); this.location = p; } // end of constructor /** Display the Calendar @date 04/28/2005 @author Jim Adams @param None @return Nothing */ public void display() { String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // Get current date Calendar today = Calendar.getInstance(); int curmonth = today.get(Calendar.MONTH); int curday = today.get(Calendar.DAY_OF_MONTH); int curyear = today.get(Calendar.YEAR); this.selected_month = Integer.toString(curmonth+1); this.selected_day = Integer.toString(curday); this.selected_year = Integer.toString(curyear); set_title(); p0.setLayout(border0); p1.setLayout(grid1); // add header row Insets insets = new Insets(1,0,2,0); // top, left, bot, right int j=0; for (j=0; j<7; j++) { headbutt[j] = new JButton(); headbutt[j].setText(headers[j]); headbutt[j].setFont(verdana9bold); headbutt[j].setMargin(insets); p1.add(headbutt[j]); } // aded data rows for (j=0; j 12) { y++; m=1; } } selected_month = String.valueOf(m); selected_day = String.valueOf(d); selected_year = String.valueOf(y); Calendar newday = Calendar.getInstance(); newday.set(Calendar.DAY_OF_MONTH, d); newday.set(Calendar.MONTH, m-1); newday.set(Calendar.YEAR, y); set_calendar_buttons(newday); set_title(); } } // end of method /** Action Listener for The Cancel Button @date 04/28/2005 @param None @author Jim Adams */ private class CancelListener implements ActionListener { public void actionPerformed( ActionEvent e ) { frame.setVisible(false); } } // end of method /** Action Listener for The Calendar Select Button @date 04/28/2005 @param None @author Jim Adams */ private class SelectListener implements ActionListener { public void actionPerformed( ActionEvent e ) { frame.setVisible(false); } } // end of method }