问一个java问题, help!,help!,help!

来源:百度知道 编辑:UC知道 时间:2024/06/19 18:35:29
在程序运行的时候,时钟没有显示!请帮忙改正!让它显示出来!谢谢!

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import java.awt.Color;
import javax.swing.Timer;
import java.util.GregorianCalendar;
import java.lang.Math;
public class Clock extends JFrame implements ActionListener{

int hour,minute,second;
Clock()
{
setTitle("时钟");
setSize(400,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Timer timer=new Timer(1000,this);
timer.start();

}
public void paintComponent(Graphics g)
{
super.paintComponents(g);
setCurrentTime();
int clockRadius=(int)(Math.min(getWidth(),getHeight())*0.4);
int xCenter=getWidth()/2;
int yCenter=getHeight()/2;
g.drawOval(xCenter-clockRadius, yCenter-clockRadius, 2*clockRadius, 2*clockRadius);

//时钟

给你改过来了可以运行
但改的不好
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import java.awt.Color;
import javax.swing.Timer;
import java.util.GregorianCalendar;
import java.lang.Math;
public class Clock {
JFrame s;
fff f;
Clock()
{ s=new JFrame();
f=new fff();
s.add(f);
s.setTitle("时钟");
s.setSize(400,500);
s.setVisible(true);
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {
new Clock();
}

}

class fff extends JPanel implements ActionListener
{/**
*
*/
private static final long serialVersionUID = 0L;
Timer timer;

public fff()
{
timer=new Timer(1000,(ActionListener) this);
timer.start();
}