package com.iflytek.day0330;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Menu;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
public class ALarmUI {
//多线程 并发编程
public static void main(String[] args) {
new ALarmUI();
JFrame jf = new JFrame("闹钟");// 创建主窗口
JLabel lab = new JLabel("当前时间:");
lab.setBounds(40, 5, 150, 60);
// 2021年3月30日 10:07:30 -> yyyy年MM月DD日 HH:mm:ss
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String now = sdf.format(new Date());
JLabel time = new JLabel(now);
time.setBounds(180, 5, 350, 60);
JPanel jp_1 = new JPanel() {
// 重写paintComponent()方法,用于面板背景图片的处理
protected void paintComponent(Graphics g) {
ImageIcon icon_1 = new ImageIcon(getClass().getResource("/images/m.png"));
Image img = icon_1.getImage();
g.drawImage(img, 0, 0, icon_1.getIconWidth(), icon_1.getIconHeight(), icon_1.getImageObserver());
jf.setSize(icon_1.getIconWidth(), icon_1.getIconHeight());
}
};
jp_1.setPreferredSize(new Dimension(500, 400));
jp_1.setLayout(null);
// 新建一个线程,专门用于处理当前时间的实时显示
new Thread(new Runnable() { // 匿名内部类
@Override
public void run() {
while (true) {
// 异常处理机制
try {
Thread.sleep(1000);// 休眠1秒
// 更新时间标签内容值
time.setText(sdf.format(new Date()));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
JLabel Reminder_1 = new JLabel("提醒时间");
Reminder_1.setBounds(40, 10, 100, 30);
String[] a = new String[] { "关闭", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
JComboBox ckbHour_1 = new JComboBox(a);
ckbHour_1.setBounds(120, 10, 60, 30);
JLabel Hour_1 = new JLabel("时");
Hour_1.setBounds(185, 10, 60, 30);
String[] q_1 = new String[] { "关闭", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45",
"46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" };
JComboBox ckbPack_1 = new JComboBox(q_1);
ckbPack_1.setBounds(210, 10, 60, 30);
JLabel Part_1 = new JLabel("分");
Part_1.setBounds(275, 10, 30, 30);
JComboBox ckbSecond_1 = new JComboBox(q_1);
ckbSecond_1.setBounds(300, 10, 60, 30);
JLabel Second_1 = new JLabel("秒");
Second_1.setBounds(365, 10, 30, 30);
JLabel Clock_1 = new JLabel("闹钟铃声");
Clock_1.setBounds(40, 50, 100, 30);
String[] s_1 = new String[] { "铃声1", "铃声2", "铃声3", "铃声4", "铃声5", "铃声6", "铃声7", "铃声8", "铃声9" };
JComboBox ckbFile_1 = new JComboBox(s_1);
ckbFile_1.setBounds(120, 50, 100, 30);
JButton off_1 = new JButton("试听");
off_1.setBounds(225, 50, 70, 30);
JLabel Text_1 = new JLabel("提醒文字");
Text_1.setBounds(40, 90, 100, 30);
JTextField Txt_1 = new JTextField("休息,休息一下吧");
Txt_1.setBounds(120, 90, 175, 30);
JLabel Repeat_1 = new JLabel("重复提醒");
Repeat_1.setBounds(40, 130, 100, 30);
JRadioButton rbNorepeat_1 = new JRadioButton("不重复");
rbNorepeat_1.setBounds(120, 130, 80, 30);
JRadioButton rbRepeat_1 = new JRadioButton("每天");
rbRepeat_1.setSelected(true);
rbRepeat_1.setBounds(200, 130, 80, 30);
ButtonGroup bg_1 = new ButtonGroup();
bg_1.add(rbRepeat_1);
bg_1.add(rbNorepeat_1);
JButton btnStart_1 = new JButton("开始定时闹钟");
btnStart_1.setBounds(120, 170, 120, 30);
jp_1.add(Reminder_1);
jp_1.add(ckbHour_1);
jp_1.add(Hour_1);
jp_1.add(ckbPack_1);
jp_1.add(Part_1);
jp_1.add(ckbSecond_1);
jp_1.add(Second_1);
jp_1.add(Clock_1);
jp_1.add(ckbFile_1);
jp_1.add(off_1);
jp_1.add(Text_1);
jp_1.add(Txt_1);
jp_1.add(Repeat_1);
jp_1.add(rbNorepeat_1);
jp_1.add(rbRepeat_1);
jp_1.add(btnStart_1);
JPanel jp_2 = new JPanel() {
protected void paintComponent(Graphics g) {
ImageIcon icon_2 = new ImageIcon(getClass().getResource("/images/n.png"));
Image img = icon_2.getImage();
g.drawImage(img, 0, 0, icon_2.getIconWidth(), icon_2.getIconHeight(), icon_2.getImageObserver());
jf.setSize(icon_2.getIconWidth(), icon_2.getIconHeight());
}
};
jp_2.setPreferredSize(new Dimension(500, 400));
jp_2.setLayout(null);
JLabel Reminder_2 = new JLabel("提醒时间");
Reminder_2.setBounds(40, 10, 100, 30);
String[] a_2 = new String[] { "关闭", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
JComboBox ckbHour_2 = new JComboBox(a_2);
ckbHour_2.setBounds(120, 10, 60, 30);
JLabel Hour_2 = new JLabel("时");
Hour_2.setBounds(185, 10, 60, 30);
String[] q_2 = new String[] { "关闭", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45",
"46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" };
JComboBox ckbPack_2 = new JComboBox(q_2);
ckbPack_2.setBounds(210, 10, 60, 30);
JLabel Part_2 = new JLabel("分");
Part_2.setBounds(275, 10, 30, 30);
JComboBox ckbSecond_2 = new JComboBox(q_2);
ckbSecond_2.setBounds(300, 10, 60, 30);
JLabel Second_2 = new JLabel("秒");
Second_2.setBounds(365, 10, 30, 30);
JLabel Clock_2 = new JLabel("闹钟铃声");
Clock_2.setBounds(40, 50, 100, 30);
String[] s_2 = new String[] { "铃声1", "铃声2", "铃声3", "铃声4", "铃声5", "铃声6", "铃声7", "铃声8", "铃声9" };
JComboBox ckbFile_2 = new JComboBox(s_2);
ckbFile_2.setBounds(120, 50, 100, 30);
JButton off_2 = new JButton("停止");
off_2.setBounds(225, 50, 70, 30);
JLabel Text_2 = new JLabel("提醒文字");
Text_2.setBounds(40, 90, 100, 30);
JTextField Txt_2 = new JTextField("休息,休息一下吧");
Txt_2.setBounds(120, 90, 175, 30);
JLabel Repeat_2 = new JLabel("重复提醒");
Repeat_2.setBounds(40, 130, 100, 30);
JRadioButton rbNorepeat_2 = new JRadioButton("不重复");
rbNorepeat_2.setBounds(120, 130, 80, 30);
JRadioButton rbRepeat_2 = new JRadioButton("每天");
rbRepeat_2.setSelected(true);
rbRepeat_2.setBounds(200, 130, 80, 30);
ButtonGroup bg_2 = new ButtonGroup();
bg_2.add(rbRepeat_2);
bg_2.add(rbNorepeat_2);
JButton btnStart_2 = new JButton("开始定时闹钟");
btnStart_2.setBounds(120, 170, 120, 30);
jp_2.add(Reminder_2);
jp_2.add(ckbHour_2);
jp_2.add(Hour_2);
jp_2.add(ckbPack_2);
jp_2.add(Part_2);
jp_2.add(ckbSecond_2);
jp_2.add(Second_2);
jp_2.add(Clock_2);
jp_2.add(ckbFile_2);
jp_2.add(off_2);
jp_2.add(Text_2);
jp_2.add(Txt_2);
jp_2.add(Repeat_2);
jp_2.add(rbNorepeat_2);
jp_2.add(rbRepeat_2);
jp_2.add(btnStart_2);
JTabbedPane tbPane = new JTabbedPane();
String[] tabNames = { "闹钟1", "闹钟2" };
tbPane.addTab(tabNames[0], jp_1);
tbPane.addTab(tabNames[1], jp_2);
tbPane.setBounds(40, 70, 500, 250);
JLabel lblMsg = new JLabel("提示");
lblMsg.setBounds(30, 340, 30, 25);
JLabel lblMsgContent = new JLabel("如果关闭程序闹钟将无法响铃,每次启动程序需要重新设置闹钟才能生效");
lblMsgContent.setBounds(30, 360, 500, 60);
jf.add(lab);
jf.add(time);
jf.add(tbPane);
jf.add(lblMsg);
jf.add(lblMsgContent);
jf.setLayout(null);
// 创建菜单栏
JMenuBar menuBar = new JMenuBar();
jf.setJMenuBar(menuBar);
// 创建一级菜单
JMenu menuFile = new JMenu("文件"), menuTool = new JMenu("工具"), menuAbout = new JMenu("关于");
menuBar.add(menuFile);
menuBar.add(menuTool);
menuBar.add(menuAbout);
// 添加一级菜单下的二级菜单
JMenu itemClock = new JMenu("新建闹钟"), itemDelete = new JMenu("删除闹钟");
menuFile.add(itemClock);
menuFile.add(itemDelete);
jf.setVisible(true);// 显示窗口
jf.setSize(600, 500);// 窗口大小
jf.validate();
}
}
看着不像web编程,有点想GUI,swing之类的
就是Swing
你的程序有什么问题?