[목차]
캘린더의 기본적인 UI를 만들어본다.
프로그램을 시작하면 위와 같이 년도와 월을 표시한다.
사용자는 <
>
버튼으로 month를 변경할 수 있다.
년도와 월이 주어졌을 때, 첫 날을 구하는 코드는 다음과 같다.
//Get first day of month and number of days
GregorianCalendar cal = new GregorianCalendar(year, month, 1);
int numberDayInMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
int firstDayOfTheWeek = cal.get(GregorianCalendar.DAY_OF_WEEK);
사용자가 임의의 날짜를 클릭하면, 그 날짜에 해당하는 [Day View Frame]을 띄운다.
왼쪽 panel
: scroll bar를 동반한 graphical panel 이다.오른쪽 panel
: 버튼 3개와, table 또는 list를 이용한 text panel 이다.public class InputDialog extends JDialog{
private String name;
private String phone;
public String getInputName(){
return name;
}
public String getInputPhone(){
return phone;
}
public InputDialog(JFrame parent) {
// set parent frame and parent frame will be infocus
super(parent,true);
// some code here ...
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
name = txtName.getText();
phone = txtPhone.getText();
// close the dialog
setVisible(false);
});
}
}