我創建了一個需要一些簡單輸入的gui應用程序,但是,當我單擊JFrame中的按鈕時,我正在使用的actionPerformed方法未被觸發/ )。我似乎無法弄清楚我已經錯過了什麼(如果有幫助,新的Java)。感謝您的任何幫助/建議。Java:actionPerformed方法在點擊按鈕時不會觸發
這裏是所有代碼:
//gui class
public class guiUser extends JFrame implements ActionListener {
private JButton buttonClose_;
private final int frameWidth = 288;
private final int frameHeight = 263;
private final int closeX = 188;
private final int closeY = 195;
private final int closeWidth = 75;
private final int closeHeight = 25;
public guiUser() {
setTitle("Create a User");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(frameWidth, frameHeight);
setResizable(false);
buttonClose_ = new JButton("Exit");
buttonClose_.setLayout(null);
buttonClose_.setSize(closeWidth, closeHeight);
buttonClose_.setBounds(closeX, closeY, closeWidth, closeHeight);
buttonClose_.setLocation(closeX, closeY);
add(buttonClose_);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonClose_) {
int result = JOptionPane.showConfirmDialog(null, "Are you sure you wish to exit user creation?");
if(result == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
}
//tests the gui
public class test {
public static void main(String args[]) {
guiUser gUser_ = new guiUser();
gUser_.setVisible(true);
}
}
請學習java命名約定並堅持到他們 – kleopatra 2012-01-04 11:31:33