怎么运用Timer和ActionListener来实现一个时钟的功能? JDK下demo下有个applet是弄时钟的 去看看吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我把你的改了一下import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.text.SimpleDateFormat;public class JClockFrame { public static void main(String[] args){ SimleFrame simpleFrame = new SimleFrame(); simpleFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); simpleFrame.show(); }}class SimleFrame extends JFrame{ public SimleFrame(){ setSize(300,80); setTitle("JClock"); ClockPanel panel = new ClockPanel(); Container contentPane = getContentPane(); contentPane.add(panel); }}class ClockPanel extends JPanel { Date curDate; public ClockPanel() { curDate= new Date(System.currentTimeMillis()); javax.swing.Timer oneSecondTimer = new javax.swing.Timer(1000,new ActionListener() { public void actionPerformed(ActionEvent e) { curDate=new Date(System.currentTimeMillis()); repaint(); } }); oneSecondTimer.start(); } public void paintComponent(Graphics g){ super.paintComponent(g); SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss "); String str = formatter.format(curDate); g.drawString(str,X,Y); } public static final int X=50; public static final int Y=50; } 正则表达式字符串中间任意匹配 struts中删除上传的文件 jna 类型转换 谁会Struts标签多行提交? java字符串转换为时间的问题 jsp页面中调用applet的问题 请教String类型变量的异或处理 菜鸟提问: 数据指针问题 JDBC中URL的问题,请教高手给详细说明一下 JAVA中记时器控件是哪个类 System.setProperty 急。。。。。。。。。。。。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.SimpleDateFormat;public class JClockFrame {
public static void main(String[] args){
SimleFrame simpleFrame = new SimleFrame();
simpleFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
simpleFrame.show();
}
}class SimleFrame extends JFrame{
public SimleFrame(){
setSize(300,80);
setTitle("JClock");
ClockPanel panel = new ClockPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}
}class ClockPanel extends JPanel {
Date curDate;
public ClockPanel()
{
curDate= new Date(System.currentTimeMillis());
javax.swing.Timer oneSecondTimer = new javax.swing.Timer(1000,new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
curDate=new Date(System.currentTimeMillis());
repaint();
}
});
oneSecondTimer.start();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
String str = formatter.format(curDate);
g.drawString(str,X,Y);
}
public static final int X=50;
public static final int Y=50;
}