您当前的位置: 首页 > 

宝哥大数据

暂无认证

  • 3浏览

    0关注

    1029博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

方法内部类

宝哥大数据 发布时间:2016-07-15 19:13:19 ,浏览量:3

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);

 

 

 

 

  }

 

}

 

关注
打赏
1587549273
查看更多评论
立即登录/注册

微信扫码登录

0.0415s