month.java
来自「这是一个在java环境下实现的日历应用程序」· Java 代码 · 共 80 行
JAVA
80 行
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 + =
减小字号Ctrl + -
显示快捷键?