关于Eclipse可以运行的java程序,cmd运行却提示主类不存在 | 您所在的位置:网站首页 › cmd找不到java源文件 › 关于Eclipse可以运行的java程序,cmd运行却提示主类不存在 |
package dti;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
public class MyJDialog extends JDialog{
public MyJDialog(MyFrame frame){
super(frame,"first",true);
Container c = getContentPane();
c.add(new JLabel("This is a Dialog"));
setBounds(120,120,100,100);
}
}
class MyFrame extends JFrame{
public void MyFrame1(String title){
Container b = getContentPane();
JLabel jl = new JLabel("This is a JFrame.");
b.add(jl);
JButton bl = new JButton("sad");
bl.setBounds(10,10,100,21);
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new MyJDialog(MyFrame.this).setVisible(true);
}
});
b.add(bl);
b.setVisible(true);
b.setSize(200, 200);
setVisible(true);
setSize(400,300);
}
public static void main(String[] args) {
new MyFrame().MyFrame1("asd");
}
}
代码如上; 上述这段代码在Eclipse中是可以完全运行的,图如下 这段代码中并没有程序的入口,也就是主方法,cmd报错也就很正常了,主方法是位于MyFrame.class这个文件中,我们来用cmd运行一下 |
CopyRight 2018-2019 实验室设备网 版权所有 |