import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;


public class JDatePanel extends JPanel implements KeyListener
{
	private String strDate;
	private String strTime;
	private String strWkDay;
	private int dowNum;
	public JLabel selectLabel = new JLabel("select an option");	
	public JLabel choiceLabel = new JLabel("'1' - display today's date    '2' - display current time    '3' - display day of week");
	public JLabel outputLabel = new JLabel("");
			
	public JDatePanel()
	{
		GregorianCalendar now = new GregorianCalendar();
		Date today = new Date();

		setLayout(new FlowLayout());
		add(selectLabel);
		add(choiceLabel);
		add(outputLabel);								
		addKeyListener(this);				
		strDate = DateFormat.getInstance().format(today);
		strTime = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(today);
		dowNum = now.get(now.DAY_OF_WEEK);
		switch(dowNum)
		{
			case 1:
				strWkDay = "Sunday";
				break;
			case 2:
				strWkDay = "Monday";
				break;				
			case 3:
				strWkDay = "Tuesday";
				break;				
			case 4:
				strWkDay = "Wednesday";
				break;				
			case 5:
				strWkDay = "Thursday";
				break;				
			case 6:
				strWkDay = "Friday";
				break;				
			case 7:
				strWkDay = "Saturday";
				break;
		}	
	}
	

	
		
		public void keyTyped(KeyEvent e)
		{
		char c = e.getKeyChar();
		if (c == '1')
			outputLabel.setText(strDate);

		else if (c == '2')
			outputLabel.setText(strTime);			
		else if (c == '3')
			outputLabel.setText(strWkDay);
		else
			outputLabel.setText("Please enter '1', '2', or '3'");					
		}

		public void keyPressed(KeyEvent e)
		{
		}
		public void keyReleased(KeyEvent e)
		{
		}		


					
	
}
