
这里是哪?#
这里是brooke_zb的个人网站,主要是研究代码用的
这里有何用?#
说实话,确实没用,只能看到我写网页的成果,当然也可以相互学习
import java.awt.*;
import java.text.SimpleDateFormat;
import javax.swing.*;
import java.util.*;
public class CrazyClock extends JFrame{
private final int WIDTH = 520; //窗口宽度
private final int HEIGHT = 500; //窗口高度
private final int WINDOWS_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width; //屏幕宽度
private final int WINDOWS_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;//屏幕高度
private final int ALARM_NUM = 2; //闹钟数量
JLabel cur_time;
TrayIcon icon;
Image img;
public CrazyClock(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(WINDOWS_WIDTH / 2 - WIDTH / 2,WINDOWS_HEIGHT / 2 - HEIGHT / 2); //使窗口在屏幕居中
//setResizable(false);
//主面板
JPanel container = new JPanel();
add(container);
container.setLayout(new FlowLayout());
//菜单栏
JMenuBar menu = new JMenuBar();
JMenu file = new JMenu("文件");
JMenu tool = new JMenu("工具");
JMenu about = new JMenu("关于");
menu.add(file);
menu.add(tool);
menu.add(about);
JMenuItem open = new JMenuItem("上传音乐");
file.add(open);
setJMenuBar(menu);
//当前时间条
JLabel cur_time_title = new JLabel("当前时间: ");
cur_time_title.setFont(new Font("宋体",Font.PLAIN,20));
container.add(cur_time_title);
cur_time = new JLabel("获取时间中...");
cur_time.setFont(new Font("宋体",Font.PLAIN,20));
cur_time.setPreferredSize(new Dimension((int)(WIDTH * 0.64), (int)(HEIGHT * 0.1)));
container.add(cur_time);
//选项卡
JTabbedPane alarm_panel = new JTabbedPane(JTabbedPane.TOP);
alarm_panel.setPreferredSize(new Dimension((int)(WIDTH * 0.84), (int)(HEIGHT * 0.5)));
JPanel[] al_con = new HomePanel[ALARM_NUM];
for (int i = 0; i < ALARM_NUM; i++) {
al_con[i] = new HomePanel();
JPanel m1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel m2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel m3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel m4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel m5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
al_con[i].add(m1);
al_con[i].add(m2);
al_con[i].add(m3);
al_con[i].add(m4);
al_con[i].add(m5);
m1.setBackground(new Color(0,0,0,0));
m2.setBackground(new Color(0,0,0,0));
m3.setBackground(new Color(0,0,0,0));
m4.setBackground(new Color(0,0,0,0));
m5.setBackground(new Color(0,0,0,0));
al_con[i].setLayout(new GridLayout(5, 1));
m1.add(new JLabel("提醒时间"));
JComboBox hour = new JComboBox<>();
hour.addItem("关闭");
for(int n = 0; n < 24; n++){
hour.addItem(n);
}
m1.add(hour);
m1.add(new JLabel("时"));
JComboBox minute = new JComboBox<>();
minute.addItem("关闭");
for(int n = 0; n < 60; n++){
minute.addItem(n);
}
m1.add(minute);
m1.add(new JLabel("分"));
JComboBox second = new JComboBox<>();
second.addItem("关闭");
for(int n = 0; n < 60; n++){
second.addItem(n);
}
m1.add(second);
m1.add(new JLabel("秒"));
m2.add(new JLabel("闹钟铃声"));
JComboBox music_choose = new JComboBox<>();
music_choose.addItem("铃声一");
music_choose.addItem("铃声二");
m2.add(music_choose);
m2.add(new JButton("试听"));
m3.add(new JLabel("提示文字"));
m3.add(new JTextField("休息,休息一下吧",8));
m4.add(new JLabel("重复提醒"));
ButtonGroup repeat = new ButtonGroup();
JRadioButton repeat_none = new JRadioButton("不重复",true);
JRadioButton repeat_day = new JRadioButton("每天提醒");
//repeat_day.setBackground(new Color(0,0,0,0));
//repeat_none.setBackground(new Color(0,0,0,0));
repeat.add(repeat_none);
repeat.add(repeat_day);
m4.add(repeat_none);
m4.add(repeat_day);
m5.setLayout(null);
JButton countdown_on = new JButton("开启定时闹钟");
countdown_on.setBounds(60, 0, 120, 30);
m5.add(countdown_on);
}
for (int i = 0; i < ALARM_NUM; i++){
String alarm_title = new String("闹钟" + (i + 1));
alarm_panel.add(alarm_title, al_con[i]);
}
container.add(alarm_panel);
JLabel tips = new JLabel(" 提示");
tips.setPreferredSize(new Dimension((int)(WIDTH * 0.92),16));
container.add(tips);
container.add(new JLabel("如果关闭程序闹钟将无法响铃,每次启动程序需要重新设置闹钟才能生效 "));
setPreferredSize(new Dimension(WIDTH, HEIGHT));
pack();
setVisible(true);
}
public static void main(String[] args){
CrazyClock clock = new CrazyClock();
//每秒获取当前系统时间并显示
while(true){
Date d = new Date();
SimpleDateFormat date_format = new SimpleDateFormat("YYYY年MM月dd日 HH时mm分ss秒");
try{
clock.cur_time.setText(date_format.format(d).toString());
Thread.sleep(1000);
}
catch (InterruptedException e){
}
}
}
}
class HomePanel extends JPanel {
ImageIcon icon;
Image img;
public HomePanel() {
icon=new ImageIcon(getClass().getResource("/HomeImg.jpg")); //读取图片
img=icon.getImage();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this); //背景图片跟随窗口自行调整大小
}
}