2017-04-08 126 views
0

我使用NetBeans IDE 8.2创建我的布局。不幸的是我无法找到的可能性超过了NetBeans GUI Builder中添加以下代码:将ActionListener添加到Netbean GUI

JButton b = new JButton("click me");  
b.addActionListener(new MyListener()); 

我发现只有一个方法,添加事件“的actionPerformed”在属性。

谢谢支持。

回答

0

您可以在构造函数中添加:

public ConstructorGUI() { 

    super.setUndecorated(true); 
    initComponents(); 
    ... 
    JButton b = new JButton("click me"); 
    b.addActionListener(new MyListener()); 
    ... 
} 

或为更好的做法,你可以创建一个分离的方法,哪些是你可以把这段代码,并调用它的构造函数。