//那个 setPreferedSize(..) 是有的, 但是解决问题也要根据实际情况
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyFrame extends JFrame
{
JButton button;
MyFrame(String s)
{
super(s);
button=new JButton("确定");
JPanel buttonJP = new JPanel();
buttonJP.add(button);
getContentPane().add(buttonJP, BorderLayout.CENTER);
addWindowListener
(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
}
);
setSize(500,300);
setVisible(true);
}
}
public class Example
{
public static void main(String args[])
{
MyFrame myFrame = new MyFrame("窗口");
}
}