package map;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class test extends JFrame {
public test() {
super("Map");
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MapPane map1=new MapPane();
Container content =(JPanel)getContentPane();
content.add(map1);
}
public static void main(String[] args) {
test Frame = new test();
Frame.show();
}
}
class MapPane extends JFrame{
public void paintComponent(Graphics comp){
Graphics comp2D =(Graphics2D)comp;
comp2D.drawString("haiwang",100,100);
}
}
编译是老出现错误(本程序是21天学通java的现成的程序):
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:616)
at java.awt.Container.add(Container.java:307)
at map.test.<init>(test.java:24)
at map.test.main(test.java:28)
Exception in thread "main"
各个大虾给说说为什么?