import java.awt.*;
import java.swing.*;public class Test extends JFrame{
public Test(){
this.setSize(780,500);
this.setDefaultCloseOperation(JFame.EXIT_ON_CLOSE);
this.setResizable(fales);
this.setTitle("测试程序!"); JPanel toolBar = new JPanel();
toolBar.setBackground(Color.white);
toolBar.setPreferredSize(new Dimension(780,48)); JPanel actionPanel = new JPanel();
actionPanel.setBackground(Color.yellow);
actionPanel.setPreferredSize(new Dimension(160,380)); JPanel contentPanel = new JPanel();
contentPanel.setBackground(Color.blue);
contentPanel.setPreferredSize(new Dimension(620,380));
this.getContentPane().add(toolBar,BorderLayout.NORTH);
this.getContentPane().add(actionPanel,BorderLayout.EAST);
this.getContentPane().add(contentPanel,BorderLayout.CENTER);
} public static void main(String args[])throws HeadlessException{
Test f1 = new Test();
Test.show();
}
}
-----------------------------------------------------------------
居然提示有16个错误
但是另外一个程序和这个几乎一模一样,就可以正常运行
到底错在哪啊?
import java.swing.*;public class Test extends JFrame{
public Test(){
this.setSize(780,500);
this.setDefaultCloseOperation(JFame.EXIT_ON_CLOSE);
this.setResizable(fales);
this.setTitle("测试程序!"); JPanel toolBar = new JPanel();
toolBar.setBackground(Color.white);
toolBar.setPreferredSize(new Dimension(780,48)); JPanel actionPanel = new JPanel();
actionPanel.setBackground(Color.yellow);
actionPanel.setPreferredSize(new Dimension(160,380)); JPanel contentPanel = new JPanel();
contentPanel.setBackground(Color.blue);
contentPanel.setPreferredSize(new Dimension(620,380));
this.getContentPane().add(toolBar,BorderLayout.NORTH);
this.getContentPane().add(actionPanel,BorderLayout.EAST);
this.getContentPane().add(contentPanel,BorderLayout.CENTER);
} public static void main(String args[])throws HeadlessException{
Test f1 = new Test();
Test.show();
}
}
-----------------------------------------------------------------
居然提示有16个错误
但是另外一个程序和这个几乎一模一样,就可以正常运行
到底错在哪啊?
import javax.swing.*;public class Test extends JFrame{
public Test(){
this.setSize(780,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("测试程序!"); JPanel toolBar = new JPanel();
toolBar.setBackground(Color.white);
toolBar.setPreferredSize(new Dimension(780,48)); JPanel actionPanel = new JPanel();
actionPanel.setBackground(Color.yellow);
actionPanel.setPreferredSize(new Dimension(160,380)); JPanel contentPanel = new JPanel();
contentPanel.setBackground(Color.blue);
contentPanel.setPreferredSize(new Dimension(620,380));
this.getContentPane().add(toolBar,BorderLayout.NORTH);
this.getContentPane().add(actionPanel,BorderLayout.EAST);
this.getContentPane().add(contentPanel,BorderLayout.CENTER);
} public static void main(String args[])throws HeadlessException{
Test f1 = new Test();
Test.show();
}
}
this.setResizable(fales); // false
Test.show(); // f1.show();
主要错误是不仔细,import java.swing.*;
这个包错了 javax..
我编译过了,提示 一个过时的方法,show()。可以执行,建议不要使用过时的方法。
setVisible(),用这个方法把!
import java.swing.*;有这个包么?应该是import javax.swing.*;巴
Test.show();show是静态方法么?,应该是f1.show();吧
this.setResizable(fales);搞错没有,fales都写出来了,是false
this.setDefaultCloseOperation(JFame.EXIT_ON_CLOSE);EXIT_ON_CLOSE不是静态的this.setDefaultCloseOperation(EXIT_ON_CLOSE);就可以了