我开始写了一个程序:
package com.bruceeckel.swing;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);
}

}
我在把这个程序用import com.bruceekel.swing;导入到下面的程序,怎么出现软件包 com.bruceeckel 不存在,运行的时候有个错误,想了半天不明白?这里那里出了问题呢,请你们帮我讲讲?
import javax.swing.*;
import java.awt.*;
import com.bruceeckel.swing;
public class Appletld extends JApplet
{
public void init()
{
getContentPane().add(new JLabel("APPlet!"));
}
public static void main(String[] args)
{
Console.run(new Appletld(),100,50);
}
}

解决方案 »

  1.   

    import com.bruceeckel.swing.*;
    swing 是一个包名,而不是类名。如果你使用import com.bruceeckel.swing;编译器认为你导入的是swing类,其所在的包为com.bruceeckel,那你运行的时候当然说这个包找不到了。
      

  2.   

    我的程序上改成import com.bruceeckel.swing.*;也不行,它说文件不包含类 Console,
    和请删除该文件或确保该文件位于正确的类路径子目录中。
                    Console.run(new Button1(),100,50);
    但是我把第一个程序保存在桌面上,第二个不能要import com.bruceeckel.swing.*;语句,才可以运行
      

  3.   

    我的程序改成import com.bruceeckel.swing.*;后,也有错
    它说:错误的类文件: E:\Thinking练习\Console.java文件不包含类 Console
                      请删除该文件或确保该文件位于正确的类路径子目录中。
                         Console.run(new Button1(),200,100);
                    ^