在下面的代码(from thinking in java)里面  Countries.capitals()应该会返回一个Map的对象
但是很明显这个代码是无法通过编译的 因为Countries并没有定义我有2个问题1. 是不是书上的代码错的 应该在前面定义一个Countries的Map2. 如果要定义 应该如何定义 谢谢诶
//: gui/TextArea.java
// Using the JTextArea control.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import net.mindview.util.*;
import static net.mindview.util.SwingConsole.*;public class TextArea extends JFrame {
  private JButton
    b = new JButton("Add Data"),
    c = new JButton("Clear Data");
  private JTextArea t = new JTextArea(20, 40);
  private Map<String,String> m =
    new HashMap<String,String>();
  public TextArea() {
    // Use up all the data:
    m.putAll(Countries.capitals());
    b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        for(Map.Entry me : m.entrySet())
          t.append(me.getKey() + ": "+ me.getValue()+"\n");
      }
    });
    c.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        t.setText("");
      }
    });
    setLayout(new FlowLayout());
    add(new JScrollPane(t));
    add(b);
    add(c);
  }
  public static void main(String[] args) {
    run(new TextArea(), 475, 425);
  }
} ///:~

解决方案 »

  1.   

    Countries 应该是在这本书的前面定义过这个类
      

  2.   


    It seems that, but i can't find it, could you pls show me the relative path of the Class Countries? I will give you all the 35 points to anyone who could help me. thx guys.
      

  3.   

    import net.mindview.util.*;
    import static net.mindview.util.SwingConsole.*;
    这两个包你引了么?  如果你没有 mindview的包.. 怎么能保证这段代码通过.   我好像记得 书上有一段国家跟首都的代码..你看看名字是不是这个..
         如果没有的话 那就肯定是包的问题.
      

  4.   

    Thinking in Java 我买的是第四版,我机器上的路径是:E:\Java编程思想源码及习题答案\源码\net\mindview\util\Countries.java
    E:\Java编程思想源码及习题答案\源码\net\mindview\util\SwingConsole.java到你自己的机器上搜一下就知道了
    好了,可以兑现你的承诺了,呵呵
      

  5.   

    找到源文件之后,将这些包导入到你的project的中就可以run了
      

  6.   

    是呀,看thinking呀,要整章看呀!如为他的代码是一章节扣一章节的呀!