addActionListener() 提示警告:构造函数中泄漏this 如题,每次调用这个函数都会提示警告,急切地想知道为什么,希望有高人能从根本上解释一下,感激不尽! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class MainFrame extends JFrame implements ActionListener { JPanel buttons = new JPanel() ; JPanel canvas = new JPanel() ; JButton btnAdd = new JButton("") ; JButton btnSetFinished = new JButton("") ; JButton btnSetUnfinished = new JButton("") ; JButton btnDelete = new JButton("") ; public MainFrame (String title) { super (title) ; this.getContentPane().add(canvas) ; this.getContentPane().add(buttons) ; this.setLayout(new FlowLayout()); buttons.add(btnAdd) ; buttons.add(btnSetFinished) ; buttons.add(btnSetUnfinished) ; buttons.add(btnDelete) ; buttons.setLayout(new GridLayout(4 , 1)) ; pack() ; this.setVisible(true) ; this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { System.exit(0); } }) ; btnAdd.addActionListener(this) ; btnSetFinished.addActionListener(this) ; btnSetUnfinished.addActionListener(this) ; btnDelete.addActionListener(this) ; } @Override public void actionPerformed(ActionEvent ae) { throw new UnsupportedOperationException("Not supported yet."); }} http://hi.csdn.net/space-8210764-do-album-picid-792773-goto-down.html elipse表示运行正常!把那句抛异常的话去掉 加上你想要申明的事件就行了。 运行确实没有问题,这只是一个"构造函数中传递可疑参数"的提示,是NetBeans7.0给的提示,也确实可以通过配置将这个设置为不提示直接忽略,但是我想知道这是怎么回事,这是否跟访问限制规则有关,直接忽略是否会留下不安全的隐患? 可以這個中文語言包是機器翻譯的,太差勁了。英文錯誤估計有人看懂,這中文不知道說的是啥,就好像“認證”這個詞,在計算機英語中有 Certification 和 Authentication 兩個詞翻譯成中文都叫“認證”,在沒有上下文的情況下,猜不出到底是哪個。要是有人工翻譯的話那就更容易懂了。 java 规律数组 过滤出 每个索引间的 规律数 有关swing的小问题 文本框等 getText()传来的的字符串 换行符 是'\n'吗? 怎么拼这个sql语句 [请教]相同的线程,重复执行的问题? 数组排序的问题,分不够可以再加? 第600分,散之 JAVA进入成熟期后将会怎样????? a little problem about the command "java" Java 都支持那些图形格式?为什么连 ICON 和 BMP 这样通用的格式都不自带支持!!!!! 怎样是一个IconImage 填满整个JButton? 非外部类引用事件监听
JPanel buttons = new JPanel() ;
JPanel canvas = new JPanel() ;
JButton btnAdd = new JButton("") ;
JButton btnSetFinished = new JButton("") ;
JButton btnSetUnfinished = new JButton("") ;
JButton btnDelete = new JButton("") ; public MainFrame (String title) {
super (title) ;
this.getContentPane().add(canvas) ;
this.getContentPane().add(buttons) ;
this.setLayout(new FlowLayout()); buttons.add(btnAdd) ;
buttons.add(btnSetFinished) ;
buttons.add(btnSetUnfinished) ;
buttons.add(btnDelete) ;
buttons.setLayout(new GridLayout(4 , 1)) ; pack() ;
this.setVisible(true) ; this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}) ;
btnAdd.addActionListener(this) ;
btnSetFinished.addActionListener(this) ;
btnSetUnfinished.addActionListener(this) ;
btnDelete.addActionListener(this) ;
} @Override
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet.");
}}
把那句抛异常的话去掉 加上你想要申明的事件就行了。