import javax.swing.*;
import java.lang.String;
import java.awt.*;
public class SketchFrame extends JFrame{
 //Constructor
 public SketchFrame(String title) {
  setTitle(title);                             //set the window title
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setJMenuBar(menuBar);                      //Add the menu bar to the window
  JMenu fileMenu = new JMenu("File");         //Creat File menu
  JMenu elementMenu = new JMenu("Elements");  //Create Elements menu
  menuBar.add(fileMenu);                      //Add the element menu
  menuBar.add(elementMenu);                   //Add the element menu
 
  }
  private JMenuBar menuBar = new JMenuBar();  //Window menu bar
  private Container pane;
  private JTextArea text;
pane = this.getContentPane();
text = new JTextArea(20,50);
this.cardlist = cardlist;
pane.setLayout(new BorderLayout());
pane.add(text); 
 
  }
 

解决方案 »

  1.   

    you meiyou ren zhidao a
      

  2.   

    把以下这些语句放到构造函数里面去就好了,试试看:)
    pane = this.getContentPane();
    text = new JTextArea(20,50);
    this.cardlist = cardlist;
    pane.setLayout(new BorderLayout());
    pane.add(text); 初始化或者直接在声明的时候完成,或者放到构造函数里进行,或者用{}扩起来,象你那样做,编译器只会提示说identifier expected。
      

  3.   

    楼上说得对,你应该先声明变量 private JMenuBar menuBar = new JMenuBar(); //Window menu bar
      private Container pane;
      private JTextArea text;至于这些变量的初始化不应该
    pane =this.getContentPane();
      text =new JTextArea(20, 50);
      this.cardlist = cardlist;
      pane.setLayout(new BorderLayout());  pane.add(text);
      

  4.   

    还是不行啊
    /Frame for the Sketcher application
    import javax.swing.*;
    import java.lang.String;
    import java.awt.*;
    public class SketchFrame extends JFrame{
     //Constructor
     public SketchFrame(String title) {
      setTitle(title);                             //set the window title
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setJMenuBar(menuBar);                      //Add the menu bar to the window
      JMenu fileMenu = new JMenu("File");         //Creat File menu
      JMenu elementMenu = new JMenu("Elements");  //Create Elements menu
      menuBar.add(fileMenu);                      //Add the element menu
      menuBar.add(elementMenu);                   //Add the element menu
        //pane.add(text);
        //pane.setLayout(new BorderLayout());
          pane = this.getContentPane();
       text = new JTextArea(20,50);             //Add the test area
         pane.setLayout(new BorderLayout());
         pane.add(text); 
      }
      private JMenuBar menuBar = new JMenuBar();  //Window menu bar
      private MainFrame text =new MainFrame();
      
      private Container pane;
     
      }
      提示::
    C:\java\HomeWork\SketchFrame.java:18: incompatible types
    found   : javax.swing.JTextArea
    required: MainFrame
       text = new JTextArea(20,50);             //Add the test area
                    ^
    1 errorProcess completed.
      

  5.   

    text 是JTextArea类型的,声明的时候为什么改成了MainFrame的了呢!
    那样当然会出错了, 把private MainFrame text =new MainFrame();改成private JTextArea text;就好了。试试吧:)
      

  6.   

    ok了!谢谢梦想啊!!!和其他帮忙的大哥!!
    不过还有一个问题啊
    这个文本文档占据了除了jmenubar以外所以的部分
    我还要在文本文档下面再一拦,左边是2个处理按纽,右边是三个输入窗口
      

  7.   


    楼上说的对
    private MainFrame text =new MainFrame();
    改成
    private JTextArea text =new JTextArea();
      

  8.   

    这个就要你自己静下心来好好看看java的布局管理器了~!