下面这段代码是我照着书本打的,用myeclipse运行,系统提示Frame cannot be resolved to a type
这是什么原因啊?
import javax.swing.*;
class SimpleFrame extends JFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame frame=new Frame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
public Frame()
{
setTitle("hello");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

        }
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=200;

}

解决方案 »

  1.   

    构造方法写错了 把public Frame()改成public SimpleFrame()。             
                  
      

  2.   


    另外Frame frame=new Frame(); 改成JFrame frame=new JFrame();
    记住:Swing中的组件的类名通常以“J”开关,如(JFrame);以区别AWT中相应的组件如(Frame)
      

  3.   

    import javax.swing.*;
    class SimpleFrame extends JFrame {
    public static void main(String[] args)
    { SimpleFrame frame=new SimpleFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //用setVisible(true)比较好
    frame.setVisible(true);
    // frame.show();过时方法
    }
    public SimpleFrame()
    {
    setTitle("hello");
    setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); }
    public static final int DEFAULT_WIDTH=300;
    public static final int DEFAULT_HEIGHT=200;}
    你只要吧你原来的代码ublic Frame()改成public SimpleFrame()。 还要把  
    Frame frame=new Frame();
    该成SimpleFrame frame=new SimpleFrame();
    就该这两行就行,其他的什么都不用改
      

  4.   

    给你推荐一本书《疯狂java讲义第二版》,里面包括最新的java7的知识。顺便把贴结一下,谢谢。多给点分啊呵呵
      

  5.   

    构造方法写错了 把public Frame()改成public SimpleFrame()。