?? 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 nextmonth,lastmonth;
MyCalendar calendar;
public Month(MyCalendar calendar)
{
super(BoxLayout.X_AXIS);
this.calendar=calendar;
showMonth=new JTextField(2);
month=calendar.getMonth( );
showMonth.setEditable(false);
showMonth.setForeground(Color.blue);
showMonth.setFont(new Font("TimesRoman",Font.BOLD,16));
nextmonth=new JButton("下月");
lastmonth=new JButton("上月");
add(lastmonth);
add(showMonth);
add(nextmonth);
lastmonth.addActionListener(this);
nextmonth.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( )==lastmonth)
{
if(month>=2)
{
month=month-1;
calendar.setMonth(month);
calendar.setcalendar(calendar.getYear( ),month);
}
else if(month==1)
{
month=12;
calendar.setMonth(month);
calendar.setcalendar(calendar.getYear( ),month);
}
showMonth.setText(" "+month);
}
else if(e.getSource( )==nextmonth)
{
if(month<12)
{
month=month+1;
calendar.setMonth(month);
calendar.setcalendar(calendar.getYear( ),month);
}
else if(month==12)
{
month=1;
calendar.setMonth(month);
calendar.setcalendar(calendar.getYear( ),month);
}
showMonth.setText(" "+month);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -