找不到符号:class java.awt.graphics

时间:2013-08-21 07:09:42

标签: java

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class string3 extends Applet implements TextListener{
Label lblMessage;
TextField txtText1;
String strString1="";
public void init(){
lblMessage=new Label("enter some words");
add(lblMessage);
txtText1.addTextListener(this);
}
public void paint(Graphics objG){
objG.drawString="strString 1,202,42";
}
public void textValueChanged(TextEvent objE){
strString1=txtText1.getText();
repaint();
}
}

cmd说

C:\ sample java> javac string3.java string3.java:14:找不到符号 symbol:变量drawString location:class java.awt.Graphics objG.drawString =“strString 1,202,42”;

1错误

1 个答案:

答案 0 :(得分:2)

drawString是一种方法而不是变量。因此,您需要将参数传递给方法而不是分配它们。你需要改变这个:

objG.drawString="strString 1,202,42";

为:

objG.drawString(strString1,202,42);