2017-04-08 76 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()); 
    ... 
} 

或爲更好的做法,你可以創建一個分離的方法,哪些是你可以把這段代碼,並調用它的構造函數。