zoukankan      html  css  js  c++  java
  • 补发《超级迷宫》站立会议八

     这天,课程较多,只在晚上搜了一段代码,进行学习,收集的代码如下:

      

    import java.awt.FlowLayout; 
    
    import java.awt.Font; 
    
    import java.awt.event.ActionEvent; 
    
    import java.awt.event.ActionListener; 
    
      
    
    import javax.swing.JButton; 
    
    import javax.swing.JFrame; 
    
    import javax.swing.JLabel; 
    
    public class Pragram { 
    
        static int seconds = 150; 
    
        private TimeThread tt = null; 
    
        private boolean ttFlag = false; 
    
          
    
        private void init() { 
    
            final JLabel tip = new JLabel(); 
    
            final JButton start = new JButton("开始"); 
    
            final JButton end = new JButton("结束"); 
    
            JFrame f = new JFrame(); 
    
            f.setLayout(new FlowLayout(5)); 
    
            f.add(tip); 
    
            f.add(start); 
    
            f.add(end); 
    
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    
            f.setVisible(true); 
    
            f.setSize(300, 150); 
    
            f.setLocationRelativeTo(null); 
    
              
    
            start.addActionListener(new ActionListener() { 
    
                  
    
                @Override 
    
                public void actionPerformed(ActionEvent e) { 
    
                    start.setEnabled(false); 
    
                    tip.setFont(new Font("宋体",Font.BOLD,27)); 
    
                    ttFlag = true; 
    
                    tt = new TimeThread(tip); 
    
                    tt.start(); 
    
                } 
    
            }); 
    
            end.addActionListener(new ActionListener() { 
    
                  
    
                @Override 
    
                public void actionPerformed(ActionEvent e) { 
    
                    start.setEnabled(true); 
    
                    tip.setText(""); 
    
                    Pragram.seconds = 150; 
    
                    ttFlag = false; 
    
                } 
    
            }); 
    
        } 
    
        /** 
    
         * @param args 
    
         */ 
    
        public static void main(String[] args) { 
    
            new Pragram().init(); 
    
        } 
    
          
    
        class TimeThread extends Thread { 
    
            private JLabel tip; 
    
            TimeThread(JLabel tip) { 
    
                this.tip = tip; 
    
            } 
    
            @Override 
    
            public void run() { 
    
                int seconds = Pragram.seconds; 
    
                tip.setText(seconds+""); 
    
                  
    
                while (seconds-- > 0 && ttFlag) { 
    
                    tip.setText(seconds+""); 
    
                    try { 
    
                        Thread.sleep(1000); 
    
                    } catch (InterruptedException e) { 
    
                        e.printStackTrace(); 
    
                    } 
    
                } 
    
            } 
    
        }; 
    
    }
    

     实现结果如下:

    如图所示,实现了倒计时。

  • 相关阅读:
    要使用springtest来进行单元测试 否则将无法注入 applicationContext.xml
    关键词的重要性
    发卡可以以交叉方式佩戴来增强可爱性
    红毛类型
    oracle学习总结4
    对springMVC的简单理解
    理解RESTful架构
    项目移植过程中报:“Project facet Java version 1.7 is not supported.” 错误
    svn服务器的搭建
    oracle学习总结3
  • 原文地址:https://www.cnblogs.com/yuntianblog/p/4591737.html
Copyright © 2011-2022 走看看