JAVA 入门 会的进

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:44:20
public class Example10_4
{
public static void main(String[]args)
{
FlowLayoutDemo f=new FlowLayoutDemo();
f.setTitle("FlowLayoutDemo");
f.setSize(200,150);
f.setLocation(400,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//这里出错 为什么
f.setVisible(true);
}
}

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
是当你关闭窗口的时候,程序也关闭了

不是你的那个f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
你的那个f是FlowLayoutDemo,这里需要一个JFrame,
需要先new 一个 JFrame 比如说 JFrame jf = new JFrame();
如果jf在某个类中的话可以直接调用this..setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

import java.awt.*;
import javax.swing.*;
引入这个类了吧?

把报错信息贴出来。

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

改成f.setDefaultCloseOperation(0); 我忘了是0还是3,你都试试吧

lastapplet 回答的很好!!顶下