month=time.get(Calendar.MONTH);它的取值为0~11的数,包括0和11,0为1月,依次类推 将取得的值加1就好了。 支持public static final int MONTH Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year. 另外 weekday=time.get(Calendar.DAY_OF_WEEK); 是不是的减1
将取得的值加1就好了。
支持public static final int MONTH
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year.
另外
weekday=time.get(Calendar.DAY_OF_WEEK);
是不是的减1
就是这样的!
多看看api是很有帮助的哦!
month=time.get(Calendar.MONTH);
它的取值为0~11的数,这好像跟下标一下,你要加回1
请详细指导,谢谢谢谢!!!
import java.applet.*;
import java.util.Calendar;
public class L9d4 extends Applet implements Runnable
{
Thread timeThread;
Font wordFont;
int year,month,day;
int weekday;
int hour,minute,second;
public void init()
{
this.setBackground(Color.black);
wordFont=new Font("楷体_gb2312",Font.BOLD,50);
}
public void start()
{
if(timeThread==null)
{
timeThread=new Thread(this);
timeThread.start();
}
}
public void stop()
{
if(timeThread!=null)
{
timeThread.stop();
timeThread=null;
}
}
public void run()
{
while(true)
{
Calendar time=Calendar.getInstance();
year=time.get(Calendar.YEAR);
month=time.get(Calendar.MONTH)+1;
day=time.get(Calendar.DAY_OF_MONTH);
weekday=time.get(Calendar.DAY_OF_WEEK)-1;
hour=time.get(Calendar.HOUR);
minute=time.get(Calendar.MINUTE);
second=time.get(Calendar.SECOND);
repaint();
try
{
Thread.sleep(300);
}
catch(InterruptedException e){}
}
}
public void paint(Graphics g)
{
String s1=year+"年"+month+"月"+day+"日";
String s2="星期"+weekday;
String s3=hour+":"+minute+":"+second;
g.setFont(wordFont);
g.setColor(Color.green);
g.drawString(s1,20,50);
g.drawString(s2,20,120);
g.drawString(s3,20,200);
}
}