当前位置: 代码迷 >> Java相关 >> 为什么会出现这样的错误呢
  详细解决方案

为什么会出现这样的错误呢

热度:209   发布时间:2007-01-22 15:15:00.0
为什么会出现这样的错误呢

//使用CustomButton 类的Averageing Applet

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

//<applet code=AverageApplet.class width=400 height=300></applet>

public class AverageApplet extends Applet implements ActionListener
{
public CustomAverage average;
public CustomButton b1;
public CustomTextField input1,input2,display;
public CustomLabel labelTitle,label1input,label2input,label3display;

public Color newColor;
public Font newFont;

public int num1,num2;

public void init()
{
Panel p1;

newColor=new Color(125,0,255);
newFont=new Font("Helvetica",Font.BOLD+Font.ITALIC,24);
average=new CustomAverage();
b1=new CustomButton("Push for Average",newColor,Color.yellow,newFont);
input1=new CustomTextField(12,"0",newColor,Color.yellow,newFont,ture);
input2=new CustomTextField(12,"0",newColor,Color.lightGray,newFont,ture);
display=new CustomTextField(12,"",newColor,Color.red,newFont,false);
LabelTitle=new CustomLabel("Average Calculator",newColor,Color.pink,newFont);
Label1input=new CustomLabel("First Number",newColor,Color.white,newFont);
Label2input=new CustomLabel("Second Number",newColor,Color.orange,newFont);
Label3display=new CustomLabel("Computed Average",newColor,Color.gray,newFont);

p1=new Panel(new GridLayout(8,1,10,10));
b1.addActionListener(this);
p1.add(labelTitle);p1.add(label1input);p1.add(input1);
p1.add(label2input);p1.add(input2);
p1.add(b1);p1.add(label3display);p1.add(display);add(p1);
}

public void actionPerformed(ActionEvent e)
{
display.setText(""+average.getAverage(Integer.parseInt(input1.getText()),
Integer.parseInt(input2.getText())));
}
/*
public void actionPerformed(ActionEvent e)
{
int num1,num2;
double avg;

num1=Integer.parseInt(input1.getText());
num2=Integer.parseInt(input2.getText());
avg=average.getAverage(num1,num2);
display.setText(""+avg);
}
*/
}



import java.awt.*;
import java.awt.event.*;
import java.applet.*;

//<applet code=CustomLabel.class width=400 height=300></applet>

public class CustomLabel extends Label
{
private Color myBackgroundColor,myForegroundColor;
private String myLabel;
private Font myFont;

public CustomLabel(String str,Color fgColor,Color bgColor,Font ft)
{
super(str);

myLabel=str;
myBackgroundColor=bgColor;
myForegroundColor=fgColor;
myFont=ft;

setBackground(myBackgroundColor);
setForeground(myForegroundColor);
setFont(ft);
}
}




import java.awt.*;
import java.awt.event.*;
import java.applet.*;

//<applet code=CustomTextField.class width=400 height=300></applet>

public class CustomTextField extends TextField
{
private Color myBackgroundColor,myForegroundColor;
private String myLabel;
private Font myFont;
private int mySize;
private boolean myCanEdit;

public CustomTextField(int size,String str,Color fgColor,Color bgColor,Font ft,boolean canEdit)
{
super(size);

myLabel=str;
myBackgroundColor=bgColor;
myForegroundColor=fgColor;
myFont=ft;
mySize=size;
myCanEdit=canEdit;

setBackground(myBackgroundColor);
setForeground(myForegroundColor);
setFont(ft);
setText(str);
setEditable(myCanEdit);
}
}

搜索更多相关的解决方案: average  display  public  import  

----------------解决方案--------------------------------------------------------
这就是错误

---------- javac ----------
AverageApplet.java:29: 找不到符号
符号: 变量 ture
位置: 类 AverageApplet
input1=new CustomTextField(12,"0",newColor,Color.yellow,newFont,ture);
^
AverageApplet.java:29: 内部错误;无法将位于 CustomTextField 的 CustomTextField(int,java.lang.String,java.awt.Color,java.awt.Color,java.awt.Font,boolean) 实例化为 ()
input1=new CustomTextField(12,"0",newColor,Color.yellow,newFont,ture);
^
AverageApplet.java:30: 找不到符号
符号: 变量 ture
位置: 类 AverageApplet
input2=new CustomTextField(12,"0",newColor,Color.lightGray,newFont,ture);
^
AverageApplet.java:30: 内部错误;无法将位于 CustomTextField 的 CustomTextField(int,java.lang.String,java.awt.Color,java.awt.Color,java.awt.Font,boolean) 实例化为 ()
input2=new CustomTextField(12,"0",newColor,Color.lightGray,newFont,ture);
^
AverageApplet.java:32: 找不到符号
符号: 变量 LabelTitle
位置: 类 AverageApplet
LabelTitle=new CustomLabel("Average Calculator",newColor,Color.pink,newFont);
^
AverageApplet.java:33: 找不到符号
符号: 变量 Label1input
位置: 类 AverageApplet
Label1input=new CustomLabel("First Number",newColor,Color.white,newFont);
^
AverageApplet.java:34: 找不到符号
符号: 变量 Label2input
位置: 类 AverageApplet
Label2input=new CustomLabel("Second Number",newColor,Color.orange,newFont);
^
AverageApplet.java:35: 找不到符号
符号: 变量 Label3display
位置: 类 AverageApplet
Label3display=new CustomLabel("Computed Average",newColor,Color.gray,newFont);
^
8 错误

输出完成 (耗时: 1 秒) - 正常终止


----------------解决方案--------------------------------------------------------

注意大小写!!!!


public CustomLabel labelTitle,label1input,label2input,label3display;这是你的定义

LabelTitle=new CustomLabel("Average Calculator",newColor,Color.pink,newFont);
Label1input=new CustomLabel("First Number",newColor,Color.white,newFont);
Label2input=new CustomLabel("Second Number",newColor,Color.orange,newFont);
Label3display=new CustomLabel("Computed Average",newColor,Color.gray,newFont);


定义的时候用小写,赋值的时候用大写,当然错了,

JAVA是大小写敏感的语言


----------------解决方案--------------------------------------------------------

还有错误。将ture改为1,false改为0后,还是报错。

---------- javac ----------
AverageApplet.java:29: 找不到符号
符号: 变量 ture
位置: 类 AverageApplet
input1=new CustomTextField(12,"0",newColor,Color.yellow,newFont,ture);
^
AverageApplet.java:29: 内部错误;无法将位于 CustomTextField 的 CustomTextField(int,java.lang.String,java.awt.Color,java.awt.Color,java.awt.Font,boolean) 实例化为 ()
input1=new CustomTextField(12,"0",newColor,Color.yellow,newFont,ture);
^
AverageApplet.java:30: 找不到符号
符号: 变量 ture
位置: 类 AverageApplet
input2=new CustomTextField(12,"0",newColor,Color.lightGray,newFont,ture);
^
AverageApplet.java:30: 内部错误;无法将位于 CustomTextField 的 CustomTextField(int,java.lang.String,java.awt.Color,java.awt.Color,java.awt.Font,boolean) 实例化为 ()
input2=new CustomTextField(12,"0",newColor,Color.lightGray,newFont,ture);
^
4 错误

输出完成 (耗时: 1 秒) - 正常终止


----------------解决方案--------------------------------------------------------
是true不是ture!!!!





----------------解决方案--------------------------------------------------------
(int,java.lang.String,java.awt.Color,java.awt.Color,java.awt.Font,boolean)

这是参数列表,你必须全部对上,才会不错

第一个是int,第二个是String,第三个是Color,第四个是Color,第五个是Font,第六个是boolean

boolean值只能是true或者false ,不能给数字]

----------------解决方案--------------------------------------------------------
建议你从最基础的学起

这些对你来说太复杂了


----------------解决方案--------------------------------------------------------

OK了!


----------------解决方案--------------------------------------------------------
以后要仔细一点,不要再犯这种低级错误了
----------------解决方案--------------------------------------------------------
  相关解决方案