监听器匿名类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了监听器匿名类相关的知识,希望对你有一定的参考价值。
// 通过匿名类实现监听器 public class ActionMonitor extends JFrame { JButton button; public ActionMonitor(){ this.setLayout(null);//布局 this.setSize(500,400);//大小 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置可以关闭 button =new JButton(); button.setBounds(200, 200, 100, 20);//位置和大小 button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } });//添加监听 this.setVisible(true);// 设置可见性 this.add(button); } public static void main(String[] args) { ActionMonitor am= new ActionMonitor(); } }
以上是关于监听器匿名类的主要内容,如果未能解决你的问题,请参考以下文章