java actionperformed_Java:actionPerformed方法在单击按钮时不触发

我正在创建一个需要一些简单输入的gui应用程序,但是,当我单击JFrame中的按钮时,我正在使用的actionPerformed方法不会被触发/触发(没有任何反应).我似乎无法弄清楚我错过了什么(如果有帮助,那就是java新手).感谢您的帮助/建议.

这是所有代码:

//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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值