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);
}
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);
}
pane = this.getContentPane();
text = new JTextArea(20,50);
this.cardlist = cardlist;
pane.setLayout(new BorderLayout());
pane.add(text); 初始化或者直接在声明的时候完成,或者放到构造函数里进行,或者用{}扩起来,象你那样做,编译器只会提示说identifier expected。
private Container pane;
private JTextArea text;至于这些变量的初始化不应该
pane =this.getContentPane();
text =new JTextArea(20, 50);
this.cardlist = cardlist;
pane.setLayout(new BorderLayout()); pane.add(text);
/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.
那样当然会出错了, 把private MainFrame text =new MainFrame();改成private JTextArea text;就好了。试试吧:)
不过还有一个问题啊
这个文本文档占据了除了jmenubar以外所以的部分
我还要在文本文档下面再一拦,左边是2个处理按纽,右边是三个输入窗口
楼上说的对
private MainFrame text =new MainFrame();
改成
private JTextArea text =new JTextArea();