package pro;import javax.swing.*;
import java.util.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Font;
public class Clock extends JFrame {
public Clock(){
this.setTitle("测试时间");
this.setResizable(false);
this.setSize(500,500);
this.setLocationRelativeTo(null);
try {
jbInit();
this.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
Clock clock = new Clock();
} private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("幼圆", Font.BOLD, 50));
jLabel1.setText("jLabel1");
jLabel1.setBounds(new Rectangle(19, 94, 521, 86));
thread ks = new thread(this);
ks.start();
ks.Run();
this.getContentPane().add(jLabel1); } JLabel jLabel1 = new JLabel();}class thread extends Thread{
Clock c = null;
public thread(Clock c){
this.c = c;
} public void Run(){
Date da = new Date();
this.c.jLabel1.setText(da.toLocaleString());
//System.out.println(da.toLocaleString());
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
}
Run();
}
}
import java.util.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Font;
public class Clock extends JFrame {
public Clock(){
this.setTitle("测试时间");
this.setResizable(false);
this.setSize(500,500);
this.setLocationRelativeTo(null);
try {
jbInit();
this.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
Clock clock = new Clock();
} private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("幼圆", Font.BOLD, 50));
jLabel1.setText("jLabel1");
jLabel1.setBounds(new Rectangle(19, 94, 521, 86));
thread ks = new thread(this);
ks.start();
ks.Run();
this.getContentPane().add(jLabel1); } JLabel jLabel1 = new JLabel();}class thread extends Thread{
Clock c = null;
public thread(Clock c){
this.c = c;
} public void Run(){
Date da = new Date();
this.c.jLabel1.setText(da.toLocaleString());
//System.out.println(da.toLocaleString());
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
}
Run();
}
}
Date da = new Date();
this.c.jLabel1.setText(da.toLocaleString());
//System.out.println(da.toLocaleString());
try {
Thread.currentThread().sleep(1000);
Thread.currentThread().run();
} catch (InterruptedException ex) {
}