如图
这个应该从什么方向入手啊?求全过程,及讲解。有哪位可以帮我一下,最好有全过程。一共有四个图片。
意思讲解如下:
如有帮助,请采纳,十分感谢!
a),b) 简单的实现代码在下面了,注释有不懂的留言。具体的显示框什么的自己查下资料
public class ClockFrame {
public static void main(String[] args) {
final JFrame clockFrame = new JFrame();
clockFrame.setLayout(new BorderLayout(10, 10));
/**网格布局,1行3列 用来放时分秒的三个label*/
JPanel clockPanel = new JPanel(new GridLayout(1, 3));
/**布局中间放置题设中的JPanel*/
clockFrame.add(clockPanel, BorderLayout.CENTER);
final JLabel amPm = new JLabel();
/**布局下方放置题设中的AM/PM label*/
clockFrame.add(amPm, BorderLayout.SOUTH);
clockFrame.setSize(new Dimension(300, 400));
final JLabel hh = new JLabel();
hh.setForeground(Color.RED);
// 设置字体大小为36pt
hh.setFont(new Font("Default", 0, 36));
final JLabel mm = new JLabel();
mm.setForeground(Color.ORANGE);
mm.setFont(new Font("Default", 0, 36));
final JLabel ss = new JLabel();
ss.setForeground(Color.BLUE);
ss.setFont(new Font("Default", 0, 36));
clockPanel.add(hh);
clockPanel.add(mm);
clockPanel.add(ss);
Timer timer = new Timer();
/** 定时任务 */
timer.schedule(new TimerTask() {
@Override
public void run() {
Calendar calendar = Calendar.getInstance();
hh.setText("" + calendar.get(Calendar.HOUR));
mm.setText("" + calendar.get(Calendar.MINUTE));
ss.setText("" + calendar.get(Calendar.SECOND));
/**判断上午还是下午*/
switch (calendar.get(Calendar.AM_PM)) {
case Calendar.PM:
amPm.setText("PM");
break;
case Calendar.AM:
default:
amPm.setText("AM");
}
}
}, 0/**0ms延时*/, 1000/**每秒执行一次*/);
clockFrame.setVisible(true);
clockFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
c),d)的话就是个进度条的简单实现,新建11给jlabel添加到panel里,然后加个键盘事件监听,监听到回车的时候就刷新一下jlabel的颜色,同时刷新最后一个jlabel的字符,睡觉了,明天有时间的话给你个实现的代码