import java.awt.Color;
import java.awt.Container;import javax.swing.JFrame;
import javax.swing.JLabel;public class JFrameDemo extends JFrame{
public JFrameDemo() { setTitle("窗口标题"); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); //隐藏窗体,并停止程序 //setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); //无任何操作 //setDefaultCloseOperation(HIDE_ON_CLOSE); //隐藏窗体,但不停止程序 //setDefaultCloseOperation(DISPOSE_ON_CLOSE); //释放窗体资源 setBounds(100, 100, 1000, 1000); Container container = getContentPane(); container.setBackground(Color.yellow); JLabel label = new JLabel("此乃一个窗体"); container.add(label); container.remove(label); container.validate(); setContentPane(container); setResizable(false);//设置窗体是否可以改变大小 System.out.println("x" + getX() + "y" + getY());}public static void main(String[] args) { new JFrameDemo();}}