📄 statusbarpanel.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -