日期:2014-05-20  浏览次数:20811 次

用命令提示符运行java程序
我在eclipse里面写了从上找的窗口程序,在eclipse里面运行很正常,但我用cmd运行时,出错了,说是找不到main函数,我又编写了一个简单的Hello Word程序,能成功运行,环境变量设置的应该没为题啊,我不知道为什么了,求高手指点下,下面是我的代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class NumberDemo extends JFrame {
private int number,i=10;//初始值为10


private JButton numBtn,m;


private Timer timer;



private class NumListener implements ActionListener {

public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
number=(int)(Math.random()*6+1);
m.setText(number + "");
i--;
if (i == 0) {
numBtn.setText("stop");
i = 10;
timer.stop();
numBtn.setEnabled(true);
}
}

}



public NumberDemo(String title) {
super(title);
//this.setBounds(400, 150, 50, 50);
m=new JButton();
m.setBounds(100, 50, 50, 50);
m.setEnabled(false);
//m.setVisible(true);
this.add(m);
numBtn = new JButton("Click");
numBtn.setBounds(0, 0, 50, 50);
numBtn.addMouseListener(new MouseListener() {

public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
if (source == numBtn && numBtn.isEnabled()) {
numBtn.setEnabled(false);
timer = new Timer(1000, new NumListener());
timer.start();
}

}


public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}


public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}


public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub

}


public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

});
this.add(numBtn);
//this.pack();
this.setBounds(400, 150, 300, 150);
//this.setLocationRelativeTo(null);
this.setLayout(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


public static void main(String[] args) {
new NumberDemo("NumberDemo");
}
}

我把包包给删了,没有导入什么包包的。求解......

------解决方案--------------------
不知道 命令行显示的 问题是什么

怎么感觉还是环境变量的问题呢~
------解决方案--------------------
java XXX
不是 java XXX.class

Exception in thread "main" java lang.NoClassDefFoundError: NumberDemo/class