这是我的一个小程序,用来显示时间的,但是程序运行后为什么不显示任何东西?
public class Date3 //这是一个显示时间的类
{
private int yy, mm, dd;
public Date3(int y, int m, int d)
{
yy = y;
if (m >= 1 && m <= 12)
{
mm = m;
}
else
mm = 1;
dd = checkDay(d);
}
private int checkDay(int d)
{
int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
if (d > 0 && d <= days[mm])
{
return d;
}
if (mm == 2 && d == 29 && (yy % 400 == 0 || (yy % 4 == 0 && yy != 0)))
{
return d;
}
return -1;
}
public String toString()
{
return yy + "/" + mm + "/" + dd;
}
public String increaseDay()
{
dd ++;
if(checkDay(dd) == -1)
{
dd = 1;
mm++;
if (mm > 12)
{
mm = 1;
yy++;
}
}
return yy + "/" + mm + "/" + dd;
}
}
import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class E0806
{
public static void main(String[] args)
{
final Date3 date = new Date3(2000,4,30);
ActionListener task = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
System.out.println(date.increaseDay());
}
};
Timer time = new Timer(500, task);
time.start();
}
}