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);
不起作用?
这个说法有什么问题吗?谁能纠正我吗?
我尝试使用参数变体调用相同的方法,例如 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
和 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
但它们都不起作用。
最佳答案
您的类应该扩展 JFrame
类:
import javax.swing.JFrame;
class Myframe extends JFrame
关于java - Jframe setDefaultCloseOperation 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34250434/