这么两个java文件
DemoMain.javapackage demo;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;import javax.swing.JButton;
import javax.swing.JFrame;
import demo.DemoFrame;/*
* Created on 2005-8-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*//**
* @author Tracy McGrady
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DemoMain extends JFrame
{
private JButton frameBtn;
public DemoMain()
{
setSize(300,200);
setTitle("Demo Test");
frameBtn = new JButton("New");
frameBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
DemoFrame newFrame = new DemoFrame();
newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFrame.show();
}
});
getContentPane().add(frameBtn,BorderLayout.CENTER);
}
public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException
{
DemoMain frame = new DemoMain();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}DemoFrame.java
package demo;
import java.awt.BorderLayout;import javax.swing.JFrame;
import javax.swing.JLabel;/*
* Created on 2005-8-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*//**
* @author Tracy McGrady
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DemoFrame extends JFrame
{
private JLabel tmacLab;
public DemoFrame()
{
setSize(300,200);
setTitle("Demo Frame");
tmacLab = new JLabel("Tracy McGrady!");
getContentPane().add(tmacLab,BorderLayout.CENTER);
}
}
这两个文件在IDE下编译运行都正常但是在CMD下
javac *.class编译出来的不能运行!!不信可以试试为什么啊??????????
DemoMain.javapackage demo;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;import javax.swing.JButton;
import javax.swing.JFrame;
import demo.DemoFrame;/*
* Created on 2005-8-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*//**
* @author Tracy McGrady
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DemoMain extends JFrame
{
private JButton frameBtn;
public DemoMain()
{
setSize(300,200);
setTitle("Demo Test");
frameBtn = new JButton("New");
frameBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
DemoFrame newFrame = new DemoFrame();
newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFrame.show();
}
});
getContentPane().add(frameBtn,BorderLayout.CENTER);
}
public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException
{
DemoMain frame = new DemoMain();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}DemoFrame.java
package demo;
import java.awt.BorderLayout;import javax.swing.JFrame;
import javax.swing.JLabel;/*
* Created on 2005-8-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*//**
* @author Tracy McGrady
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DemoFrame extends JFrame
{
private JLabel tmacLab;
public DemoFrame()
{
setSize(300,200);
setTitle("Demo Frame");
tmacLab = new JLabel("Tracy McGrady!");
getContentPane().add(tmacLab,BorderLayout.CENTER);
}
}
这两个文件在IDE下编译运行都正常但是在CMD下
javac *.class编译出来的不能运行!!不信可以试试为什么啊??????????
请用javac -d .*.java
编译执行的时候用
java demo.DemoMain 命令看来你初学就用IDE啊~~
这可不好:)
javac -d . *.java
第一个点是当前文件夹的意思~`
前后都要空格啊