java报错 expected什么意思啊?

fullmoon525 2003-06-14 01:06:06
同上
...全文
11800 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hohona 2003-06-15
  • 打赏
  • 举报
回复
这个就要你自己静下心来好好看看java的布局管理器了~!
fullmoon525 2003-06-15
  • 打赏
  • 举报
回复
ding @
icewhite 2003-06-14
  • 打赏
  • 举报
回复

楼上说的对
private MainFrame text =new MainFrame();
改成
private JTextArea text =new JTextArea();
fullmoon525 2003-06-14
  • 打赏
  • 举报
回复
ok了!谢谢梦想啊!!!和其他帮忙的大哥!!
不过还有一个问题啊
这个文本文档占据了除了jmenubar以外所以的部分
我还要在文本文档下面再一拦,左边是2个处理按纽,右边是三个输入窗口
hohona 2003-06-14
  • 打赏
  • 举报
回复
text 是JTextArea类型的,声明的时候为什么改成了MainFrame的了呢!
那样当然会出错了, 把private MainFrame text =new MainFrame();改成private JTextArea text;就好了。试试吧:)
fullmoon525 2003-06-14
  • 打赏
  • 举报
回复
还是不行啊
/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 error

Process completed.
dooby 2003-06-14
  • 打赏
  • 举报
回复
应该把变量的初始化放在方法里面执行
dooby 2003-06-14
  • 打赏
  • 举报
回复
楼上说得对,你应该先声明变量

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);
hohona 2003-06-14
  • 打赏
  • 举报
回复
把以下这些语句放到构造函数里面去就好了,试试看:)
pane = this.getContentPane();
text = new JTextArea(20,50);
this.cardlist = cardlist;
pane.setLayout(new BorderLayout());
pane.add(text);

初始化或者直接在声明的时候完成,或者放到构造函数里进行,或者用{}扩起来,象你那样做,编译器只会提示说identifier expected。
fullmoon525 2003-06-14
  • 打赏
  • 举报
回复
you meiyou ren zhidao a
fullmoon525 2003-06-14
  • 打赏
  • 举报
回复
ding @
fullmoon525 2003-06-14
  • 打赏
  • 举报
回复
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);

}
dooby 2003-06-14
  • 打赏
  • 举报
回复
大哥把源码贴出来啊 这样没有几个人能答出来

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧