public class MainFrame extends JFrame{    static final int WIDTH=850;
    static final int HEIGHT=450;
    JButton buttonk = new JButton();
    buttonk.setSize(150,150);     这一行提示错误
}
求高手指教

解决方案 »

  1.   

    你写的位置不对,需要在方法当中写才行public class MainFrame extends JFrame{  static final int WIDTH=850;
      static final int HEIGHT=450;
      JButton buttonk = new JButton();
    //  buttonk.setSize(150,150);
        private void init(){
        buttonk.setSize(150,150);
    }}
      

  2.   

    如果你使用了布局管理器,setSize方法基本被忽略。这时使用 setPreferredSize。
    使用了绝对布局的,使用 setBounds 设置大小位置解决了就结贴吧。