下面这段代码是我照着书本打的,用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;
}
这是什么原因啊?
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;
}
解决方案 »
- NotWritablePropertyException求解决
- 大家进来发表下意见吧,关于J道中的思想!
- 要求同时做B/S和C/S的界面,还要求程序模块化,现在正在为选择技术而犯愁
- 请高手赐教!版主帮我顶啊!谢谢!
- 数据库编程
- 一个简单问题?
- 关于日期(Date)的问题!
- 如何识别出0开头或0x开头的int类型?
- 请问在哪里能下载都这些东西!(散分了~~)
- 谁有办法用java执行于java.exe不在一个目录的class文件?
- eclipse下如何将程序打包成 可以双击执行的Jar文件
- Java String怎样实现 temp.replaceLast(regex,replacement)???
另外Frame frame=new Frame(); 改成JFrame frame=new JFrame();
记住:Swing中的组件的类名通常以“J”开关,如(JFrame);以区别AWT中相应的组件如(Frame)
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();
就该这两行就行,其他的什么都不用改