Topic: 紧急求救,在线等回答,,,为什么会是这样?(运行时月会提前一个月) |
Print this page |
1.紧急求救,在线等回答,,,为什么会是这样?(运行时月会提前一个月) | Copy to clipboard |
Posted by: wxfk12345 Posted on: 2005-12-04 08:50 本程序是完成显示系统当前时间的,为什么编译通过后,,系统日期是显示前一个月?郁闷中,本人是新手,不太了解,请各位高手们指导指导. 程序代码如下: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; public class FrameTime extends JFrame implements Runnable,ActionListener { private Thread duke; private JLabel yy,mm,dd,hh,ii,ss; private JButton stopst; private boolean flag; private JPanel pan; public static void main(String[] dd) { FrameTime tt = new FrameTime(); tt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tt.show(); } public FrameTime() { setTitle("当前时间"); yy= new JLabel(); mm= new JLabel(); dd= new JLabel(); hh= new JLabel(); ii= new JLabel(); ss= new JLabel(); stopst= new JButton("开始"); pan= new JPanel(); // pan.setLaout(new BorderLayout()); pan.add(yy); pan.add(mm); pan.add(dd); pan.add(hh); pan.add(ii); pan.add(ss); pan.add(stopst); getContentPane().add(pan); setSize(300,100); stopst.addActionListener(this); } public void start() { flag=true; duke=new Thread(this); duke.start(); } public void stop() { flag=false; duke=null; } public void actionPerformed(ActionEvent d) { boolean boo=(duke==null); if(boo) { stopst.setText(boo?"暂停":"开始"); start(); } else { stopst.setText(boo?"暂停":"开始"); stop(); } } public void run() { while(flag) { repaint(); GregorianCalendar cale = new GregorianCalendar(); yy.setText(cale.get(Calendar.YEAR)+"年 "); mm.setText(cale.get(Calendar.MONTH)+"月"); dd.setText(cale.get(Calendar.DATE)+"日"); hh.setText(cale.get(Calendar.HOUR)+"时"); ii.setText(cale.get(Calendar.MINUTE)+"分"); ss.setText(cale.get(Calendar.SECOND)+"秒"); } } } 不知怎么会这样,本人在线等您的指导. |
2.Re:紧急求救,在线等回答,,,为什么会是这样? [Re: wxfk12345] | Copy to clipboard |
Posted by: wmgreat Posted on: 2005-12-04 09:23 0月=1月,Calendar类是从0开始记数的 |
3.Re:紧急求救,在线等回答,,,为什么会是这样? [Re: wxfk12345] | Copy to clipboard |
Posted by: wxfk12345 Posted on: 2005-12-04 11:11 哦,谢谢~ |
4.Re:紧急求救,在线等回答(运行时为什么月会提前一个月) [Re: wmgreat] | Copy to clipboard |
Posted by: why Posted on: 2005-12-04 11:21 Don't double-post!! 请尽量使用准确的文字描述作为标题 (甚至只是简单的错误信息) 若新帖再無恰当标题,可能会被刪除 http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#MONTH The first month of the year is JANUARY which is 0 http://java.sun.com/j2se/1.4.2/docs/api/constant-values.html#java.util.Calendar.DECEMBER public static final int DECEMBER 11 public static final int DST_OFFSET 16 public static final int ERA 0 public static final int FEBRUARY 1 public static final int FIELD_COUNT 17 public static final int FRIDAY 6 public static final int HOUR 10 public static final int HOUR_OF_DAY 11 public static final int JANUARY 0 public static final int JULY 6 public static final int JUNE 5 public static final int MARCH 2 public static final int MAY 4 public static final int MILLISECOND 14 public static final int MINUTE 12 public static final int MONDAY 2 public static final int MONTH 2 public static final int NOVEMBER 10 public static final int OCTOBER 9 |
5.Re:紧急求救,在线等回答,,,为什么会是这样? [Re: wxfk12345] | Copy to clipboard |
Posted by: wxfk12345 Posted on: 2005-12-04 11:31 哦,~~~~明白了,我会注意的,谢谢提醒. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |