public void g()
里的void要去掉,否则就不是构造函数了。

解决方案 »

  1.   

    public void g()
    里的void要去掉,否则就不是构造函数了。
      

  2.   

    同意wangyuanzju(breezes) 
    构造方法没有返回类型
    public void g()  //这里的void去掉,改为public g()
    {
    setTitle("记事本");
    JButton bt=new JButton("ok");
    JTextArea ar=new JTextArea(20,10);
    add (bt);
    add (ar);
    setMenu();
    pack ();
    setVisible (true);

    }
      

  3.   

    你没有加容器。
    import javax.swing.*;
    //import javax.swing.event.*;
    import java.awt.*;

    public class t
    {
        public static void main(String args[])
        {
         a frame=new a();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.show();
        }
    }
    class a extends JFrame
    {

    Container c;
    public a()
    {

    c=getContentPane(); JButton bt=new JButton("ok");
    JTextArea ar=new JTextArea(20,10);
    c.add(bt);
    c.add(ar);
    setMenu();
    pack ();
    setSize(300,300);
    c.show();

    } public void setMenu()
    {
    JMenuBar menuBar = new JMenuBar();
    JMenuItem fileMenu=new JMenuItem("file");
    setJMenuBar(menuBar);
    menuBar.add(fileMenu);

    }
    }
      

  4.   

    Swing 的JFrame不能直接用add  直接用add的是awt的Frame 
    JFrame要先有一个容器 再用容器的addContainer contentPane=getContentPane();  //contentPane 是容器
    contentPane.add(new JButton("ok"));
    contentPane.add(new JTextArea(20,10));public  g()  //同意楼上几位老大 这个是构造函数 不能有返回类型