单击按钮关闭JFrame [英] Closing JFrame with button click

查看:109
本文介绍了单击按钮关闭JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有JFrame的jButton1私有成员,我想在单击按钮时关闭框架。

I have the jButton1 private member of JFrame and i wanted to close the frame when the button is clicked.

jButton1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    {
    }
});

我想做 super.close()但是找不到超级优惠。有没有办法引用JFrame

I wanted to do super.close() but could not find close for super. Is there some way to refer to the JFrame

推荐答案

你需要引用你要关闭的特定帧但是假设你引用 dispose()应该关闭框架。

You will need a reference to the specific frame you want to close but assuming you have the reference dispose() should close the frame.

jButton1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    {
       frameToClose.dispose();
    }
});

这篇关于单击按钮关闭JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆