我创建了一个需要一些简单输入的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