Java Reference
In-Depth Information
5.
import java.awt.event.ActionListener;
6.
import javax.swing.JComboBox;
7.
import javax.swing.JLabel;
8.
import javax.swing.JPanel;
9.
10.
public class CalendarPanel extends JPanel {
11.
private String[] months = {"January","February","March","April",
12.
"May","June","July","August",
13.
"September","October","November","December"};
14.
private JComboBox yearBox = new JComboBox();
15.
private JComboBox monthBox = new JComboBox(months);
16.
private JComboBox dayBox
= new JComboBox();
17.
private JLabel yearLabel
= new JLabel("Year ");
18.
private JLabel monthLabel
= new JLabel("Month ");
private JLabel dayLabel
= new JLabel("Day ");
19.
private JLabel dummy
= new JLabel("");
20.
private int startyear;
21.
private int endyear;
22.
23.
24.
public CalendarPanel() {
this .setLayout( new GridLayout(4,2));
25.
startyear = 2004;
26.
27.
endyear
= 2007;
28.
initBoxes();
29.
this .add(dayLabel);
30.
this .add(dayBox);
31.
this .add(monthLabel);
32.
this .add(monthBox);
33.
this .add(yearLabel);
34.
this .add(yearBox);
35.
this .add(dummy);
36.
37.
yearBox.setEditable( true );
38.
CalenderListener cList = new CalenderListener();
39.
yearBox.setActionCommand("YearChanged");
40.
yearBox.addActionListener(cList);
monthBox.setActionCommand("MonthChanged");
41.
monthBox.addActionListener(cList);
42.
}
43.
44.
45.
private void initBoxes()
{
46.
for ( int y=startyear;y <= endyear;y++ )
47.
{
48.
49.
yearBox.addItem(Integer.toString(y));
50.
}// for
51.
for ( int d=1;d<=31 ;d++ )
Search WWH ::




Custom Search