这两个文件都放在同一目录E:\test\kaishi的目录下,路径设置为:javac -classpath c:\programFile\Java\jdk1.5.0_04\lib E:\test\kaishi\console.java
在test\kaishi目录下生成console.class文件,但运行E:\test\kaishi> javac button.java
提示:
button.java:1:软件包 kaishi 不存在
import kaishi.console;
^
button.java:30: 找不到符号
符号: 类 Buttons
位置: 类 button
Console.run(new Buttons(),350,100);
^
button.java:30: 找不到符号
符号: 变量 Console
位置: 类 button
Console.run(new Buttons(),350,100);
package kaishi;
import javax.swing.*;
import java.awt.event.*;
public class console{
public static String title(Object o){
String t=o.getClass().toString();
if(t.indexOf( "class ")!=-1)
t=t.substring(6);
return t;
}
public static void run(JFrame frame,int width,int height){
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width,height);
frame.setVisible(true);
}
public static void run(JApplet applet,int width,int height){
JFrame frame=new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width,height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void run(JPanel panel,int width,int height){
JFrame frame=new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
import kaishi.console;
import javax.swing.*;
import java.awt.*;
import javax.swing.plaf.basic.*;
import javax.swing.border.*;
public class button extends JApplet{
private JButton jb=new JButton( "JBtton ");
private BasicArrowButton
up=new BasicArrowButton(BasicArrowButton.NORTH),
down=new BasicArrowButton(BasicArrowButton.SOUTH),
right=new BasicArrowButton(BasicArrowButton.EAST),
left=new BasicArrowButton(BasicArrowButton.WEST);
public void init(){
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(jb);
cp.add(new JToggleButton( "JToggleButton "));
cp.add(new JCheckBox( "JCheckBox "));
cp.add(new JRadioButton( "JRadioButton "));
JPanel jp=new JPanel();
jp.setBorder(new TitledBorder( "Directions "));
jp.add(up);
jp.add(down);
jp.add(left);
jp.add(right);
cp.add(jp);
}
public static void main(String[] args){