-3
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 位置: class java.awt.Graphics objG.drawString="strString 1,202,42";

1 个错误

4

1 回答 1

2

drawString是方法而不是变量。所以你需要将参数传递给方法而不是分配它们。你需要改变这个:

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

到:

objG.drawString(strString1,202,42);
于 2013-08-21T07:12:06.640 回答