简单程序javac成功,可是运行无内容显示

Gere Yeung 2005-11-24 07:43:49
程序如下,请指教,谢谢。

import java.awt.*;
import javax.swing.*;
import java.util.*;

public class DigitalClock extends JFrame
{
WatchPanel watch = new WatchPanel();

public DigitalClock()
{
super("Digital Clock");
setSize(1024, 576);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(1, 1, 15, 15));
pane.add(watch);
setContentPane(pane);
this.setVisible(true);
}

public static void main(String args[])
{
DigitalClock dc = new DigitalClock();
}
}

class WatchPanel extends JPanel implements Runnable
{
Thread runner;

WatchPanel()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}

public void run()
{
while (true)
{
repaint();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e) {}
}
}

public void paintCommponent(Graphics comp)
{
Graphics2D comp2D = (Graphics2D)comp;
Font type = new Font("Jean", Font.BOLD, 18);
comp2D.setFont(type);
comp2D.setColor(getBackground());
comp2D.fillRect(0, 0, getSize().width, getSize().height);
GregorianCalendar day = new GregorianCalendar();
String time = day.getTime().toString();
comp2D.setColor(Color.blue);
comp2D.drawString(time, 5, 24);
}
}
...全文
259 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Clove 2005-11-25
  • 打赏
  • 举报
回复
必须改
差一下JDK HELP
jxufewbt 2005-11-25
  • 打赏
  • 举报
回复
paintCommponent
改成
paintComponent

Gere Yeung 2005-11-25
  • 打赏
  • 举报
回复
为什么?
believefym 2005-11-24
  • 打赏
  • 举报
回复
paintComponent

not

paintCommponent

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧