?? month.java
字號:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Month extends Box implements ActionListener
{
int month;
JTextField showMonth=null;
JButton 下月,上月;
CalendarPad 日歷;
public Month(CalendarPad 日歷)
{
super(BoxLayout.X_AXIS);
this.日歷=日歷;
showMonth=new JTextField(2);
month=日歷.getMonth();
showMonth.setEditable(false);
showMonth.setForeground(Color.blue);
showMonth.setFont(new Font("TimesRomn",Font.BOLD,16));
下月=new JButton("下月");
上月=new JButton("上月");
add(上月);
add(showMonth);
add(下月);
上月.addActionListener(this);
下月.addActionListener(this);
showMonth.setText(""+month);
}
public void setMonth(int month)
{
if(month<=12&&month>=1)
{
this.month=month;
}
else
{
this.month=1;
}
showMonth.setText(""+month);
}
public int getMonth()
{
return month;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==上月)
{
if(month>=2)
{
month=month-1;
日歷.setMonth(month);
日歷.設置日歷牌(日歷.getYear(),month);
}
else if(month==1)
{
month=12;
日歷.setMonth(month);
日歷.設置日歷牌(日歷.getYear(),month);
}
showMonth.setText(""+month);
}
else if(e.getSource()==下月)
{
if(month<12)
{
month=month+1;
日歷.setMonth(month);
日歷.設置日歷牌(日歷.getYear(),month);
}
else if(month==12)
{
month=1;
日歷.setMonth(month);
日歷.設置日歷牌(日歷.getYear(),month);
}
showMonth.setText(""+month);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -