栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Swing计时器暂时隐藏通知

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Swing计时器暂时隐藏通知

javax.swing.Timer
有初步的延迟;只需将其设置为即可
60* 60 * 1000
actionPerformed()
调用后一个小时,您将被呼叫
start()

附录:这是一个按钮示例,该按钮在指定的时间段内隐藏了它的封闭窗口。

import java.awt.EventQueue;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.Jframe;import javax.swing.Timer;public class Timerframe extends Jframe {    private void display() {        this.setTitle("Timerframe");        this.setLayout(new GridLayout(0, 1));        this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);        this.add(new TimerButton("Back in a second", 1000));        this.add(new TimerButton("Back in a minute", 60 * 1000));        this.add(new TimerButton("Back in an hour", 60 * 60 * 1000));        this.pack();        this.setLocationRelativeTo(null);        this.setVisible(true);    }        private class TimerButton extends JButton {        private final Timer timer;        public TimerButton(String text, int delay) { super(text); this.addActionListener(new StartListener()); timer = new Timer(delay, new StopListener());        }        private class StartListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) {     Timerframe.this.setVisible(false);     timer.start(); }        }        private class StopListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) {     timer.stop();     Timerframe.this.setVisible(true); }        }    }    public static void main(String[] args) {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     new Timerframe().display(); }        });    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/569369.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号