程序如下,请指教,谢谢。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);
}
}
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);
}
}
解决方案 »
- 帮忙解决问题
- 怎么高效地按比特写入文件?
- Scanner 这个类大家用得多吗?我觉得还不如用BufferedReader习惯。
- SQL Server2000的存储过程如果有2个以上不同的select语句在JAVA中如何得到这几个结果集?
- 请问怎么改变java sound的音量?
- 怎样将一个数组的所有元素都清理为0???
- j2se中读取TXT文件时第一行出现“?”的问题。
- sp3的补丁打了,可是还是出先这个问题,是什么原因啊??没分了
- 请问,在JAVA中如何得到当前CLASS的当前路径?
- 菜鸟请教:我下了一个freeJava,怎么编译程序(程序没问题)没反应,它的JDk目录我也设了d:\jdk.3(JDK1.3不是安装的,是从JBuilder5直接里复制放在d:\jdk1.3里),用别的工具都可以编译成功!
- string类型
- 定义String时出错.大家来看看!
改成
paintComponent