//Clock.java
package eduCondition;
import java.sql.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.text.SimpleDateFormat;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
public class Clock extends JPanel implements Runnable, ActionListener {
private String str = "";
private int x;
private Font font = new Font("Serif", Font.BOLD, 20);
private Color color = new Color(200, 255, 200);
private JButton b_login;
private SimpleDateFormat bartDateFormat = new SimpleDateFormat("各位老师学生,你们好! 今天是 yyyy年 MM月 dd日 EEEE HH:mm:ss");
public Clock() {
setOpaque(false);
Thread c = new Thread(this);
c.start();
setLayout(null);
b_login = new JButton("登陆");
b_login.addActionListener(this);
b_login.setFont(font);
b_login.setBackground(color);
b_login.setBounds((int)(getWidth() / 8), (int)(getHeight() / 2), getWidth() / 10, getHeight() / 12);
add(b_login);
}
public void run() {
while (true) {
try {
Thread.sleep(50);
str = bartDateFormat.format(new Date());
x += 1;
if (x > this.getWidth()) {
x = -380;
}
repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void paintComponent(Graphics g) {
g.drawString(str, x, (int)(getHeight() / 4));
b_login.setBounds((int)(getWidth() / 8), (int)(getHeight() / 2), getWidth() / 10, getHeight() / 12);
Date str = new Date();
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == b_login) {
LogIn lg = new LogIn();
b_login.setVisible(false);
}
repaint();
}
}