springboot mybatis-plus swing实现报警监听

news2024/9/27 6:40:57

通过声音控制报警器,实现声光报警,使用beautyeye_lnf.jar美化界面如下
在这里插入图片描述
在这里插入图片描述

@EnableTransactionManagement(proxyTargetClass = true)
@SpringBootApplication
@EnableScheduling
public class AlarmWarnApplication {

    public static void main(String[] args) {
        try {
            org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;
            UIManager.put("RootPane.setupButtonVisible", false);
        } catch(Exception e) {
            //TODO exception
        }
        new SpringApplicationBuilder(AlarmWarnApplication.class).headless(false).run(args);
        //显示界面
        ViewStart.run();
    }

}
public class ViewStart {
    public static void run() {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    SpringContextUtils.getBean(SwingArea.class).setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
@Component("SwingArea")
@Scope("prototype") //创建多例
@SuppressWarnings("all")
public class SwingArea extends JFrame {
    private ImageIcon imageIcon;
    private URL url;
    private JLabel imageLabel;
    private JLabel label;
    private JButton openBtn;
    private Timer timer;
    private AudioPlay audioPlay;

    @Autowired
    private DevicealarmMapper devicealarmMapper;

    public SwingArea() {
    	//报警要加载的音乐
        InputStream inputStream = getClass().getResourceAsStream("/music/music.wav");
        System.out.println(inputStream);
        audioPlay = new AudioPlay(inputStream);
        setTitle("报警监听程序");
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                // 处理关闭事件,例如显示确认对话框
                int option = JOptionPane.showConfirmDialog(SwingArea.this, "确定要关闭报警监听吗?", "提示", JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_OPTION) {
                    // 用户确认关闭,执行关闭操作
                    dispose();
                }
            }
        });
        setResizable(false);
        setLayout(null);
        //尺寸
        setSize(800, 500);
		//背景图片
        ((JPanel)this.getContentPane()).setOpaque(false);
        url = this.getClass().getResource("/music/green.png");
        imageIcon = new ImageIcon(url); //添加图片
        imageLabel = new  JLabel(imageIcon);
        imageLabel.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
        getLayeredPane().add(imageLabel, new Integer(Integer.MIN_VALUE));


        label = new JLabel("无报警");
        label.setFont(new Font(null, Font.BOLD, 30));
        label.setForeground(new Color(91, 182, 91));
        label.setBounds(120, -60, 500, 200);
        label.setHorizontalAlignment(JLabel.CENTER);
        add(label);

        openBtn = new JButton("消音");
        openBtn.setBounds(295,320,144,60);
        openBtn.setBackground(new Color(255,255,255));
        openBtn.setFont(new Font("宋体", Font.BOLD,28));
        openBtn.setForeground(Color.red);//字体颜色
        openBtn.setRolloverEnabled(true);
        //更改鼠标移入按钮背景色一直不起作用
//        openBtn.addMouseListener(new MouseAdapter() {
//            @Override
//            public void mouseEntered(MouseEvent e) {
//                // 鼠标进入时设置悬浮颜色
//                openBtn.setBackground(new Color(255,219,213 ));
//            }
//            @Override
//            public void mouseExited(MouseEvent e) {
//                // 鼠标离开时设置背景颜色
//                openBtn.setBackground(new Color(255,255,255));
//            }
//        });
        openBtn.setVisible(false);
        add(openBtn);

        setVisible(true);
        QueryWrapper<Devicealarm> queryWrapper = new QueryWrapper<>();
        //未消音
        queryWrapper.eq("mute", 0);
        //未处理
        queryWrapper.eq("isprocessing", 0);

        // 定时器,对报警监听
        timer = new Timer(2000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                java.util.List<Devicealarm> devicealarms = devicealarmMapper.selectList(queryWrapper);
                if(devicealarms.size() > 0){
                    //动态更改背景图重点,要先进行remove
                    getLayeredPane().remove(imageLabel);
                    label.setBounds(120, -30, 500, 200);
                    label.setFont(new Font(null, Font.BOLD, 28));
                    url = this.getClass().getResource("/music/alarm.gif");
                    imageIcon = new ImageIcon(url); //添加图片
                    imageLabel = new  JLabel(imageIcon);
                    imageLabel.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
                    getLayeredPane().add(imageLabel, new Integer(Integer.MIN_VALUE));

                    openBtn.setVisible(true);
                    setVisible(true);
                    setExtendedState(JFrame.NORMAL);
                    toFront();
                    java.util.List<String> messageArr = new ArrayList<>();
                    java.util.List<String> idArr = new ArrayList<>();
                    for(int i = 0; i < devicealarms.size(); i++){
                        messageArr.add(devicealarms.get(i).getName() + "报警,浓度" + devicealarms.get(i).getValue() + "%LEL");
                        idArr.add(devicealarms.get(i).getId());
                    }
                    String message = "<html>" + String.join("<br/>", messageArr) + "</html>";
                    label.setText(message);
                    label.setForeground(Color.RED);
                    audioPlay.start();
                    openBtn.addActionListener(it -> {
                    	//动态更改背景图重点,要先进行remove
                        getLayeredPane().remove(imageLabel);
                        url = this.getClass().getResource("/music/green.png");
                        imageIcon = new ImageIcon(url); //添加图片
                        imageLabel = new  JLabel(imageIcon);
                        imageLabel.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
                        getLayeredPane().add(imageLabel, new Integer(Integer.MIN_VALUE));
                        getLayeredPane().repaint();
                        openBtn.setVisible(false);

                        Devicealarm devicealarm = new Devicealarm();
                        devicealarm.setMute(1);
                        devicealarmMapper.update(devicealarm, new QueryWrapper<Devicealarm>().in("id", idArr));
                        audioPlay.pause();
                        label.setForeground(new Color(91, 182, 91));
                        label.setBounds(120, -60, 500, 200);
                        label.setText("<html>无报警</html>");
                    });
                }
            }
        });
        // 启动定时器
        timer.start();
    }
}

其他工具类

@Component
public class SpringContextUtils implements ApplicationContextAware {
    /**
     * 上下文对象实例
     */
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    /**
     * 获取applicationContext
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    /**
     * 通过name获取 Bean.
     *
     * @param name
     * @return
     */
    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }

    /**
     * 通过class获取Bean.
     *
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }

    /**
     * 通过name,以及Clazz返回指定的Bean
     *
     * @param name 标识名
     * @param clazz 类型对象
     * @param <T>
     * @return
     */
    public static <T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }
}
@Component
public class SpringContextUtils implements ApplicationContextAware {
    /**
     * 上下文对象实例
     */
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    /**
     * 获取applicationContext
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    /**
     * 通过name获取 Bean.
     *
     * @param name
     * @return
     */
    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }

    /**
     * 通过class获取Bean.
     *
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }

    /**
     * 通过name,以及Clazz返回指定的Bean
     *
     * @param name 标识名
     * @param clazz 类型对象
     * @param <T>
     * @return
     */
    public static <T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1396772.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

51单片机中断系统编程

一.外部中断 1.编程思想 中断准备&#xff1a;中断初始化函数打开中断开关 &#xff0c;选择中断传输方式中断处理&#xff1a;为了便于观察&#xff0c;让我们知道单片机进入中断处理函数&#xff0c;在这里我们选择打开流水灯电路搭建&#xff1a;由于P3^3引脚不便直接接地…

C# ObjectArx 绘制表格并设置单元格合并

第一行默认是标题&#xff0c;可设置行【RowType】进行设置类型 Document doc Application.DocumentManager.MdiActiveDocument;using (Transaction tr doc.TransactionManager.StartOpenCloseTransaction()){BlockTable bt tr.GetObject(doc.Database.BlockTableId, OpenMo…

vue列表飞入效果

效果 实现代码 <template><div><button click"add">添加</button><TransitionGroup name"list" tag"ul"><div class"list-item" v-for"item in items" :key"item.id">{{ i…

conda 安装, 配置以及使用

文章目录 1. 安装2. 配置2.1 如何配置2.2 快速设置取消自动进入 base 环境conda 添加清华源pip 添加清华源pip 更新为最新版本 3. 使用 conda 是 python 的环境管理工具包&#xff0c;非常好用&#xff0c;特别是 miniconda 相对于 conda 不需要安装其他的工具&#xff0c;而且…

从临床和科研场景分析ChatGPT在医疗健康领域的应用可行性

2023年4月发表在Journal Medical Systems的文献《Evaluating the Feasibility of ChatGPT in Healthcare: An Analysis of Multiple Clinical and Research Scenarios》&#xff08;评估 ChatGPT 在医疗健康领域的可行性&#xff1a;对多种临床和研究场景的分析&#xff09;介绍…

Rust-泄漏

在C中&#xff0c;如果引用计数智能指针出现了循环引用&#xff0c;就会导致内存泄漏。而Rust中也一样存在引用计数智能指针Rc,那么Rust中是否可能制造出内存泄漏呢? 内存泄漏 首先&#xff0c;我们设计一个Node类型&#xff0c;它里面包含一个指针&#xff0c;可以指向其他…

Python的OpenCV模块实现图像转换素描图简单示例

一、示例代码&#xff1a; import cv2img cv2.imread(/home/lijiang/图片/ubuntu_wallpaper/Einstein_2.jpg) # 读取图像grey cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 灰度 invert cv2.bitwise_not(grey)blur_img cv2.GaussianBlur(invert…

Postgresql数据库死锁

死锁报错1 UPDATE deadlock_example SET value value 1 WHERE id 1ERROR: deadlock detected DETAIL: Process 95 waits for ShareLock on transaction 3553457; blocked by process 187. Process 187 waits for ShareLock on transaction 3553458; blocked by process 95.…

串联RLC电路中的增益

在串联RLC电路中&#xff0c;增益又可以叫放大倍数&#xff0c;用M或者G表示 电压增益就是输出电压比输入电压&#xff0c;MVo/Vin 在串联RLC中&#xff0c;VoIr*Rac,VinIr*(sLr1/sCrRac) MRac/(sLr1/sCrRac) 当输入频率fs时&#xff0c;fr为谐振频率 输入频率0<fs<…

贯通用友T+与企企,引领企业数字化转型新篇章!

客户介绍&#xff1a; 某科技有限公司是一家专注于高端芯片研发和制造的高科技企业。自成立以来&#xff0c;该企业始终坚持以科技创新为核心&#xff0c;致力于为全球客户提供高性能、高品质的芯片解决方案。公司拥有一支由业内资深专家和优秀工程师组成的研发团队&#xff0…

带你学C语言-指针(4)

目录 ​编辑 ⚾0.前言 &#x1f3c0;1.回调函数 ⚽2.qsort &#x1f3c9;2.1 qsort函数的模拟实现 &#x1f3be;3.sizeof与strlen对比 &#x1f3be;4.结束语 ⚾0.前言 言C之言&#xff0c;聊C之识&#xff0c;以C会友&#xff0c;共向远方。各位CSDN的各位你们好啊&…

selenium处理下拉框

当想要爬取的数据由下拉框来选择时&#xff0c;应该如何处理&#xff1f; 页面如下&#xff1a; 目的获得电影的详细信息&#xff0c;包括票房&#xff0c;上映日期等。 代码如下&#xff1a; from selenium import webdriver from selenium.webdriver.support.select impor…

28个炫酷的CSS特效动画示例(含源代码)

CSS是网页的三驾马车之一&#xff0c;是对页面布局的总管家&#xff0c;2024年了&#xff0c;这里列出28个超级炫酷的CSS动画示例&#xff0c;让您的网站更加炫目多彩。 文章目录 1. 涌动的弹簧效果2. 超逼真的3D篮球弹跳&#xff0c;含挤压弹起模态3. 鼠标放div上&#xff0c;…

linux磁盘,分区,挂载等等

1. 修改磁盘分区的标签 例如&#xff1a;733be18b-7baf-d84c-879d-ca3db465f179太长了&#xff0c;修改一下。 linuxchenxiao:/media/linux/733be18b-7baf-d84c-879d-ca3db465f179$ 先 sudo blkid sudo blkid 找到你想修改的UUID(唯一标识符) /dev/sda1: UUID"733be…

VBA_MF系列技术资料1-315

MF系列VBA技术资料 为了让广大学员在VBA编程中有切实可行的思路及有效的提高自己的编程技巧&#xff0c;我参考大量的资料&#xff0c;并结合自己的经验总结了这份MF系列VBA技术综合资料&#xff0c;而且开放源码&#xff08;MF04除外&#xff09;&#xff0c;其中MF01-04属于…

【LeetCode热题100】【子串】滑动窗口最大值

题目 给你一个整数数组 nums&#xff0c;有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。 返回 滑动窗口中的最大值 。 示例 1&#xff1a; 输入&#xff1a;nums [1,3,-1,-3,5,3,6,7], …

华尔街日报:中国加密货币交易“非法却盛行”,VPN翻墙、微信找币商、线下面交……

《华尔街日报》戏谑地称&#xff0c;中国的投资者曾经是加密货币交易的主导力量&#xff0c;人民币是用于交易比特币最受欢迎的法定货币。而现在&#xff0c;中国的币圈投资者正努力规避政府对加密货币交易的严格规定。 事实上&#xff0c;在过去几年里&#xff0c;中国大陆与加…

基于springboot+vue的旅游网站系统(前后端分离)

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战 主要内容&#xff1a;毕业设计(Javaweb项目|小程序等)、简历模板、学习资料、面试题库、技术咨询 文末联系获取 项目背景…

各模块的实现

注册模块&#xff1a; 注册使用手机号发送验证码注册的方式&#xff0c;使用的是阿里云的短信发送服务&#xff0c;然后进行认证&#xff0c;有个60s的时间&#xff0c;可以存到redis中&#xff0c;key是手机号&#xff0c;value是验证码。 使用Spring自带的BCryptPasswordEn…

什么是OSPF?为什么需要OSPF?OSPF基础概念

什么是OSPF&#xff1f; 开放式最短路径优先OSPF&#xff08;Open Shortest Path First&#xff09;是IETF组织开发的一个基于链路状态的内部网关协议&#xff08;Interior Gateway Protocol&#xff09;。 目前针对IPv4协议使用的是OSPF Version 2&#xff08;RFC2328&#x…