如题,我下载了think in Java 书中的源代码,但是我在测试这些代码的时候发现总是提示“import 。”包不存在,我该怎样才能把这些包导入进去,我用的IDE是netbeans 6.8 ,请高手指教,我是不是要重新打包啊,具体该怎么做。 
如:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import static net.mindview.util.SwingConsole.*;   //此包没有,但SwingConsole这个程序有,我该怎样打包,而且我下载的源代码里有很多程序都要导入自己以前创建的包,难道我要不我下载的源代码中的几百个程序一一运行打包才行吗?public class FileChooserTest extends JFrame {
  private JTextField
    fileName = new JTextField(),
    dir = new JTextField();
  private JButton
    open = new JButton("Open"),
    save = new JButton("Save");
  public FileChooserTest() {
    JPanel p = new JPanel();
    open.addActionListener(new OpenL());
    p.add(open);
    save.addActionListener(new SaveL());
    p.add(save);
    add(p, BorderLayout.SOUTH);
    dir.setEditable(false);
    fileName.setEditable(false);
    p = new JPanel();
    p.setLayout(new GridLayout(2,1));
    p.add(fileName);
    p.add(dir);
    add(p, BorderLayout.NORTH);
  }
  class OpenL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      JFileChooser c = new JFileChooser();
      // Demonstrate "Open" dialog:
      int rVal = c.showOpenDialog(FileChooserTest.this);
      if(rVal == JFileChooser.APPROVE_OPTION) {
        fileName.setText(c.getSelectedFile().getName());
        dir.setText(c.getCurrentDirectory().toString());
      }
      if(rVal == JFileChooser.CANCEL_OPTION) {
        fileName.setText("You pressed cancel");
        dir.setText("");
      }
    }
  }
  class SaveL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      JFileChooser c = new JFileChooser();
      // Demonstrate "Save" dialog:
      int rVal = c.showSaveDialog(FileChooserTest.this);
      if(rVal == JFileChooser.APPROVE_OPTION) {
        fileName.setText(c.getSelectedFile().getName());
        dir.setText(c.getCurrentDirectory().toString());
      }
      if(rVal == JFileChooser.CANCEL_OPTION) {
        fileName.setText("You pressed cancel");
        dir.setText("");
      }
    }
  }
  public static void main(String[] args) {
    run(new FileChooserTest(), 250, 150);
  }
}

解决方案 »

  1.   

    你如果是想"只包裝你程式用到的"那些類別,那問題沒你想的這麼簡單。
    因為有可能你用到的類別還會使用其他類別,所以最後你根本檢查不完。
    最簡單方法就是,你用到那些jar就一併放到你的程式library路徑。
      

  2.   

    import static net.mindview.util.SwingConsole.*; //此包没有你要知道这个包是在哪个jar里,然后在netbeans里选择项目-库,鼠标右键,选择“添加JAR/文件夹”,添加你需要的jar包。
      

  3.   

    书中载这个例子前面先写了一个显示框架的例子,这个就是引入了这个例子,用于显示的,不用每次都设置
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300,100);
    frame.setVisible(true);