statusbarpanel.java
来自「网络代理服务器的设计与实现 实现对网络的管理」· Java 代码 · 共 57 行
JAVA
57 行
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class statusBarPanel extends JPanel{
public static JLabel taskLabel;
public static JLabel timeLabel;
private Timer time;
public statusBarPanel(){
this.setLayout(new GridLayout());
taskLabel=new JLabel("Hello this is a taskBar!",SwingConstants.LEFT);
JSeparator s=new JSeparator(JSeparator.VERTICAL);
Dimension ps=s.getPreferredSize();
timeLabel=new JLabel("",SwingConstants.RIGHT);
this.add(taskLabel);
this.add(s);
this.add(timeLabel);
s.setPreferredSize(new Dimension(2,20));
time=new Timer();
time.start();
}
private class Timer extends Thread {
private Date now;
int hours;
int minutes;
int seconds;
public Timer(){}
public void run()
{
now = new Date();
try
{
while(true)
{
hours = now.getHours();
minutes = now.getMinutes();
seconds = now.getSeconds();
String timeValue = "" + hours;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeLabel.setText(timeValue+" ");
Thread.sleep(1000);
now.setTime(now.getTime() + 1000);
}
}
catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?