Jframe setDefaultCloseOperation不起作用 [英] Jframe setDefaultCloseOperation not working

查看:63
本文介绍了Jframe setDefaultCloseOperation不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import javax.swing.*;
import java.awt.*;
class Myframe extends Frame
{
    private JButton btn;
    private JTextArea txtarea;
    Myframe()
    {
        super("Saibaba");
        setLayout(new BorderLayout());
        btn=new JButton("CLICK Me");
        txtarea=new JTextArea();
        add(txtarea,BorderLayout.CENTER);
        add(btn,BorderLayout.SOUTH);
        setSize(500,600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //this isnt working.
        setVisible(true);
    }

    public static void main(String args[])
    {
        Myframe m=new Myframe();

    }
}

为什么此 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 不起作用?这句话怎么了?谁能纠正我?

Why is this setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); not working? What's wrong with this statement? Can anyone correct me?

我尝试使用参数变体(例如 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); )调用同一方法和 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ,但它们都不起作用.

I have tried calling same Method with parameter variants like setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); and setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); but none of them is working.

推荐答案

您的类应扩展 JFrame 类:

import javax.swing.JFrame;

class Myframe extends JFrame

这篇关于Jframe setDefaultCloseOperation不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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