• 16.24


     1 import javax.swing.*;
     2 import java.awt.*;
     3 import java.awt.event.*;
     4 
     5 public class Test_16_24 extends JFrame{
     6     JPanel butJP= new JPanel();
     7     StillClock clock = new StillClock();
     8     JButton jb1 = new JButton("start");
     9     JButton jb2 = new JButton("stop");
    10     Timer timer = new Timer(1000,new ActionListener(){
    11         @Override
    12         public void actionPerformed(ActionEvent e) {
    13             // TODO Auto-generated method stub
    14             clock.setCurrentTime();
    15             clock.repaint();
    16         }        
    17     });
    18     
    19     public Test_16_24(){        
    20         butJP.add(jb1);
    21         butJP.add(jb2);
    22         add(butJP,BorderLayout.SOUTH);
    23         add(clock,BorderLayout.CENTER);
    24         //start event listener
    25         jb1.addActionListener(new ActionListener(){
    26 
    27             @Override
    28             public void actionPerformed(ActionEvent arg0) {
    29                 // TODO Auto-generated method stub                
    30                 timer.start();
    31             }
    32             
    33         });
    34         //stop event listener
    35         jb2.addActionListener(new ActionListener(){
    36 
    37             @Override
    38             public void actionPerformed(ActionEvent arg0) {
    39                 // TODO Auto-generated method stub
    40                 timer.stop();
    41             }
    42             
    43         });
    44         
    45     }
    46     
    47     public static void main(String[] args) {
    48         // TODO Auto-generated method stub
    49         JFrame frame = new Test_16_24();
    50         frame.setTitle("Test_16_24");
    51         frame.setSize(300, 300);
    52         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    53         frame.setLocationRelativeTo(null);
    54         frame.setVisible(true);
    55     }
    56 
    57 }
    Test_16_24.java
  • 相关阅读:
    hadoop_05
    分布式集群时间同步
    crontab定时任务
    操作系统笔记五:输入输出系统
    操作系统笔记四:文件管理与磁盘存储器管理
    操作系统笔记三:存储器管理
    操作系统笔记二:进程与调度(2)
    操作系统笔记二:进程与调度(1)
    可能的加分项
    对老师的建议
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5682972.html
Copyright © 2020-2023  润新知