Topic: 这个程序怎么会有3个错误?

  Print this page

1.这个程序怎么会有3个错误? Copy to clipboard
Posted by: sxjy
Posted on: 2004-12-03 07:18

我用Freejava调试了这个程序,怎么出现下面三个错误?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FrameDempl
{
  public static void main(String args[])
  {
    Jframe frame=new Jframe("Exam10.1");
    Container c=frame.getContentPane();
    c.setLayout(new FlowLayoutDemo());
    Jlabel 1b=new JLabel("FrameDemo");
    JTextField tf=new JTextField("TextField");
    JButton bt1=new JButton("Button");
    JButton bt2=new JButton("Button");
    c.add(1b);
    c.add(tf);
    c.add(bt1);
    c.add(bt2);
    frame.setSize(400,100);
    frame.show();
    frame.addWindowListener(new WindowAdapter()
    {
     public void windowClosing(WindowEvent e)
     {
     System.exit(0);
}
});     
  }
}

编译后:

FrameDempl.java:12: not a statement
    Jlabel 1b=new JLabel("FrameDemo");
^
FrameDempl.java:12: ';' expected
    Jlabel 1b=new JLabel("FrameDemo");
^
FrameDempl.java:16: ')' expected
    c.add(1b);
^
3 errors
Exit code: 1
There were errors

2.Re:这个程序怎么会有3个错误? [Re: sxjy] Copy to clipboard
Posted by: miaomiao9527
Posted on: 2004-12-03 15:01

你没有和类JFramed建立继承关系
public class FrameDempl extends JFarmed

3.Re:这个程序怎么会有3个错误? [Re: sxjy] Copy to clipboard
Posted by: tcxmn
Posted on: 2004-12-08 00:03

这个_______
Jframe frame=new Jframe("Exam10.1");
Jframe 应该改成JFrame, 大写啊!

Jlabel 1b=new JLabel("FrameDemo");
是JLabel 大写啊!
还有这个应该是lb,你写成1234 的1b了,变量名应该以字母开头的

c.setLayout(new FlowLayoutDemo());??
这个FlowLayoutDemo是什么东东?
改成c.setLayout(new FlowLayout());
__________________________________________
正确的代码如下
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FrameDemo1 {
public static void main(String args[]) {
JFrame frame = new JFrame("Exam10.1");
Container c = frame.getContentPane();
c.setLayout(new FlowLayout());

JLabel lb = new JLabel("FrameDemo");
JTextField tf = new JTextField("TextField");
JButton bt1 = new JButton("Button");
JButton bt2 = new JButton("Button");
c.add(lb);
c.add(tf);
c.add(bt1);
c.add(bt2);
frame.setSize(400, 100);
frame.show();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}

4.Re:这个程序怎么会有3个错误? [Re: sxjy] Copy to clipboard
Posted by: tcxmn
Posted on: 2004-12-08 00:06

这里将FrameDemp1 改成了public class FrameDemo1 (Demo是演示的意思)
这个无关紧要


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923