[英]error in running frame program in java
I compiled the program it has no error but while running I get an error:我编译了程序,它没有错误,但在运行时出现错误:
could not find or load frame.java
找不到或无法加载 frame.java
I saved program name as frame.java
and run as java frame.java
我将程序名称保存为
frame.java
并作为java frame.java
运行
import java.awt.*;
import java.awt.event.*;
public class frame extends Frame {
Label l1, l2, l3, l4, l5, l6;
frame() {
super("my frame title");
setLayout(new FlowLayout());
l1 = new Label("name");
l2 = new Label("fathers name");
l3 = new Label("add");
l4 = new Label("sex");
l5 = new Label("course");
l6 = new Label("hobbies");
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
}
);
}
public static void main(String a[]) {
frame o = new frame();
o.setSize(500, 500);
o.setVisible(true);
}
}
A Java source file is compiled into a file of {name}.class.一个Java 源文件被编译成一个{name}.class 文件。
But when running the class file, you don't need to supply the .class
prefix, for example...但是在运行类文件时,您不需要提供
.class
前缀,例如...
java frame
Another problem you might have is that there is an expectation that a class should belong to a package and you may have difficulty finding/running a class within the default package, for example...您可能遇到的另一个问题是,期望一个类应该属于一个包,并且您可能很难在默认包中找到/运行一个类,例如......
package test;
import java.awt.*;
import java.awt.event.*;
public class frame extends Frame {
Label l1, l2, l3, l4, l5, l6;
frame() {
super("my frame title");
setLayout(new FlowLayout());
l1 = new Label("name");
l2 = new Label("fathers name");
l3 = new Label("add");
l4 = new Label("sex");
l5 = new Label("course");
l6 = new Label("hobbies");
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
}
);
}
public static void main(String a[]) {
frame o = new frame();
o.setSize(500, 500);
o.setVisible(true);
}
}
The source file will now need to be saved in the test
directory and compiled using something like...源文件现在需要保存在
test
目录中并使用类似...
javac test\frame.java
And run using something like并使用类似的东西运行
java test.frame
Assuming your are executing from the parent directory of the test
directory假设您是从
test
目录的父目录执行
See Creating and Using Packages for more details.有关更多详细信息,请参阅创建和使用包。
I'd also recommend that:我还建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.