zoukankan      html  css  js  c++  java
  • 方法内部类

    public  AlarmLock{

      private int delay;

      private int flag;

      public AlarmLock(int delay,int flag){

      this.delay = delay;

      this.flag = flag ;

      }

      提供一个方法供外部使用

      public  void start(){

      //创建一个方内部类

        class Printer implements ActionListener(ActionEvent e){

        //将时间转化为格式化字符串

        DateFormate format = new SimpleDateFormate("hh:mm:ss");

        String   result = format.format(new Date());

        System.out.println("当前时间:"+result);

        if(flag){

          Tookit.getDefaultToolkit().beep();

        }

        } 

      }

      new Timer(delay,new Printer()).start();

    }

    public class Test{

      public static void main(String[] args){

      AlarmClork clork = new AlarmClock(100,true);

      clock.start();

      JOptionPane.showMessageDialog(null ,"是否退出");

      System.exit(0);

      }

    }

  • 相关阅读:
    P1064 金明的预算方案
    P1164 小A点菜
    P1346 电车
    01背包二进制优化
    2018暑期多校1
    牛课第二次多校I
    STL
    Reachability from the Capital
    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
    P3387 【模板】缩点
  • 原文地址:https://www.cnblogs.com/chengbao/p/4822899.html
Copyright © 2011-2022 走看看