以下是我自己写的源程序,但只能显示一个静态时间,我们老师的要求是,要显示动态时间,就是只要系统的时间变,显示的时间也跟着变的那种。
然后请在我的程序上做改动就好了。谢谢,必定追加20分以上。
老师的要求是这样的:在一个有限次循环中,对Update方法产生调用并检测其返回值,若返回true则显示当前系统时间(年-月-日 时:分:秒)。
用该静态类测试类MyTime,看能否产生一个数字时钟的效果?
package a;
import java.util.*;
class MyTime {
private int year, month, day, hour, minute, second;
MyTime(int year,int month,int day,int hour,int minute,int second){
this.year=year;
this.month=month;
this.day=day;
this.hour=hour;
this.minute=minute;
this.second=second;
}
void setMyTime(int year,int month,int day,int hour,int minute,int second) { // 入口方法
this.year=year; //入口
this.month=month;
this.day=day;
this.hour=hour;
this.minute=minute;
this.second=second;
}
double getyear() { return year; } // 出口方法
double getmonth() { return month;}
double getday() { return day;}
double gethour() { return hour;}
double getminute() { return minute;}
double getsecond() { return second;}
}
public class AA {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH) + 1;
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
MyTime mytime=new MyTime(year,month, day,hour, minute, second);
System.out.print(year+" 年"+month+"月"+day+"日");
System.out.println(hour+" 时"+minute+"分"+second+"秒");
}
}
conse是什么?我是如此地新手,才学了两个星期。
本回答被提问者采纳