F:\java>javac Applet1d.java
Applet1d.java:10: cannot access Console
bad class file: .\Console.class
class file contains wrong class: library.tools.Console
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
                Console.run(new Applet1d(),100,50);
                ^
1 errorF:\java>

解决方案 »

  1.   

    这是thinking in java例子吗?你有没有从头看起啊?
    Console是那个作者写的一个类
      

  2.   

    对啊,看来你是行家啊,我是借这个例子来学习包的概念,当Applet1d.java和Console.java放在同一个文件夹并不使用包的时候,是正确的,但是我的classpath设置的都正确,如果classpath不正确,complier会提示cannot find symbol。我搞不懂啊!
      

  3.   

    Applet1d.java:如下:import javax.swing.*;
    import java.awt.*;
    import library.tools.*;public class Applet1d extends JApplet{
    public void init(){
    getContentPane().add(new JLabel("Applet!"));
    }
    public static void main(String[] args){
    Console.run(new Applet1d(),100,50);
    }
    }Console.java如下:package library.tools;
    import javax.swing.*;
    import java.awt.event.*;public class Console
    {
    //Create a title string from the class name.
    public static String title(Object o)
    {
    String t=o.getClass().toString();
    //Remove the word "class".
    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);
    }
    }classpath中有F:\java;
    F:\java\library\tools\