我看到API的东西都介绍的很详尽,想请教一下比如:
 Frame f=new Frame();
这个Frame构造函数有4种
 public JFrame() throws HeadlessException {
        super();        
        frameInit();
    }
    public JFrame(GraphicsConfiguration gc) {
        super(gc);
        frameInit();
    }    public JFrame(String title) throws HeadlessException {
        super(title);
        frameInit();
    }
        public JFrame(String title, GraphicsConfiguration gc) {
        super(title, gc);
        frameInit();
    }
而我对应的是
1Frame f=new Frame();
2Frame f=new Frame(GraphicsConfiguration gc)看了ApI还是不知道这个怎么写
3 Frame f=new Frame("aaa");我就是想请教一下那些都是列出来的如果继承他们的子类如何写构造函数,我怎么还是不知道我上面第二个例子到底怎么写啊

解决方案 »

  1.   

    是根据你传进来的参数决定的,1Frame f=new Frame()没有参数传进,就应调用第一种构造函数,
    2Frame f=new Frame(GraphicsConfiguration gc)调用第二种构造函数,
    Frame f=new Frame("aaa");调用第二种构造函数,
      

  2.   

    不好意思上面写错了,修改:
    Frame f=new Frame("aaa");调用第三种构造函数,
    如果还有Frame f=new Frame("aaa",GraphicsConfiguration gc);就调用第四种,
      

  3.   

    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  JPanel
    {
        public static void main(String arg[])
        {  GraphicsConfiguration g;
           
             JPanel p=new JPanel(g );//为何这么写不对呢
             
         
           
        }
    }
      

  4.   

    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  JPanel
    {
        public static void main(String arg[])
        {  
           
             JPanel p=new JPanel(GraphicsConfiguration g );//这样写才对,
             
         
           
        }
    }
      

  5.   

    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  JPanel
    {
        public static void main(String arg[])
        {  
           
             JPanel p=new JPanel(GraphicsConfiguration g );//这样写才对,
             
         
           
        }
    }这样也不对啊??说g那里有错误
      

  6.   

    JPanel p=new JPanel(GraphicsConfiguration[] g )这样呢?
      

  7.   

    JPanel p=new JPanel(GraphicsConfiguration[] g )这样呢?也不对啊
      

  8.   

    挖刚查了一下,JPanel的构造方法如下:JPanel() 
    JPanel(boolean isDoubleBuffered)
    JPanel(LayoutManager layout) 
    JPanel(LayoutManager layout, boolean isDoubleBuffered) 创建新对象时,参数不是GraphicsConfiguration对象啊,所以肯定还是不行的
      

  9.   

    如果用JPanel创建新对象,则参数应该是它构造函数中支持的类型的,这里不支持GraphicsConfiguration对象的,所以如果你要用JPanel的话,只能传这三种:空,boolean,LayoutManager不是任何一个对象都可以的
      

  10.   


    晕了,我刚写的是Frame的,一下子写成了JPanel,先谢谢你哈,我按照api写了可是还是有问题
    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  Frame
    {
        public static void main(String arg[])
        {  
         Frame f=new Frame(GraphicsConfiguration g);//还是不对
        
             
         
           
        }
    }
    还有这个
    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  JPanel
    {
        public static void main(String arg[])
        { 
         JPanel p=new JPanel(LayoutManager layout );//layout那里有问题
        
         
           
        }
    }
      

  11.   

    我知道了,这样就对了
    import java.awt.*;import javax.swing.JPanel;public class Untitled1 extends  JPanel
    {static LayoutManager layout
        public static void main(String arg[])
        { 
         JPanel p=new JPanel(layout );
        
         
           
        }
    }
      

  12.   

    哦想起来了,你应该再import进LayoutManager,