質問内容
質問を評価する
(0ポイント)
|
初心者なのでくだらない質問かもしれませんが教えてもらえると助かります
Javaで時計をリアルタイムに表示するアプリケーションを作ろうと思い
public class Timer361 extends TimerTask{ static JLabel label; static SimpleDateFormat format; public static void main(String[]args){ JFrame frame=new JFrame(); Timer361 frame2=new Timer361(); frame.add(label,BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } Timer361(){ label =new JLabel(); label.setPreferredSize(new Dimension(700,700)); label.setFont(new Font("Dialog",Font.BOLD,30)); format=new SimpleDateFormat("HH:MM:SS"); Timer timer=new Timer(); timer.schedule(this,0,1000); } synchronized public void run(){ Calendar calendar=Calendar.getInstance(Locale.JAPAN); label.setText(format.format(calendar.getTime())); } }
というコードを書いてみたのですが 全然正常に作動しません(秒針が三ケタになったり、でたらめな時間だったりが表示され、秒針が動かない) どこがまずいのでしょうか?
|