⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 month.java

📁 这是一个在java环境下实现的日历应用程序
💻 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 + -