当前位置: 技术问答>java相关
请问这段代码在编译是怎么总是报错呢??
来源: 互联网 发布时间:2015-10-25
本文导语: import java.applet.*; import java.awt.*; class Xiyoujipeople { float height,weight; String head,foot,hand,mouth; String speak(String s) { return s; } public class Example4_4 extends Applet { Xiyoujipeople sunwukong,zhubajie; String s1,s2; { sunwukong=ne...
import java.applet.*;
import java.awt.*;
class Xiyoujipeople
{
float height,weight;
String head,foot,hand,mouth;
String speak(String s)
{
return s;
}
public class Example4_4 extends Applet
{
Xiyoujipeople sunwukong,zhubajie;
String s1,s2;
{
sunwukong=new Xiyoujipeople();
zhubajie=new Xiyoujipeople();
zhubajie.weight=200f;
zhubajie.height=1.70f;
zhubajie.head="大头";
zhubajie.mouth="大嘴";
zhubajie.foot="两只脚";
zhubajie.hand="黑手";
sunwukong.weight=10000.0f;
sunwukong.height=1.60f;
sunwukong.head="一头秀发";
sunwukong.mouth="樱桃小口";
sunwukong.foot="两只小脚";
sunwukong.hand="白嫩小手";
s1="我是猪八戒,做梦都想娶媳妇";
s2="我是悟空,想骗猪八戒背我";
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString(zhubajie.head+zhubajie.mouth+zhubajie.hand+zhubajie.foot+zhubajie.hand,5.10);
g.drawString("重量"+zhubajie.weight+"高"+zhubajie.height,5,30);
g.drawString(zhubajie.speak(s1),5,10);
g.setColor(Color.green);
g.drawString(sunwukong.head+sunwukong.mouth+sunwukong.hand+sunwukong.foot+sunwukong.hand,5.70);
g.drawString(sunwukong.speak(s1),5,90);
g.drawString("嘿嘿老孙重:"+sunwukong.weight,5,110);
}
}
}
报错内容:
D:JAVAExample4_4.java:36: cannot resolve symbol
symbol : method drawString (java.lang.String,double)
location: class java.awt.Graphics
g.drawString(zhubajie.head+zhubajie.mouth+zhubajie.hand+zhubajie.foot+zhubajie.hand,5.10);
^
D:JAVAExample4_4.java:40: cannot resolve symbol
symbol : method drawString (java.lang.String,double)
location: class java.awt.Graphics
g.drawString(sunwukong.head+sunwukong.mouth+sunwukong.hand+sunwukong.foot+sunwukong.hand,5.70);
^
2 errors
请问怎么回事啊????
import java.awt.*;
class Xiyoujipeople
{
float height,weight;
String head,foot,hand,mouth;
String speak(String s)
{
return s;
}
public class Example4_4 extends Applet
{
Xiyoujipeople sunwukong,zhubajie;
String s1,s2;
{
sunwukong=new Xiyoujipeople();
zhubajie=new Xiyoujipeople();
zhubajie.weight=200f;
zhubajie.height=1.70f;
zhubajie.head="大头";
zhubajie.mouth="大嘴";
zhubajie.foot="两只脚";
zhubajie.hand="黑手";
sunwukong.weight=10000.0f;
sunwukong.height=1.60f;
sunwukong.head="一头秀发";
sunwukong.mouth="樱桃小口";
sunwukong.foot="两只小脚";
sunwukong.hand="白嫩小手";
s1="我是猪八戒,做梦都想娶媳妇";
s2="我是悟空,想骗猪八戒背我";
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString(zhubajie.head+zhubajie.mouth+zhubajie.hand+zhubajie.foot+zhubajie.hand,5.10);
g.drawString("重量"+zhubajie.weight+"高"+zhubajie.height,5,30);
g.drawString(zhubajie.speak(s1),5,10);
g.setColor(Color.green);
g.drawString(sunwukong.head+sunwukong.mouth+sunwukong.hand+sunwukong.foot+sunwukong.hand,5.70);
g.drawString(sunwukong.speak(s1),5,90);
g.drawString("嘿嘿老孙重:"+sunwukong.weight,5,110);
}
}
}
报错内容:
D:JAVAExample4_4.java:36: cannot resolve symbol
symbol : method drawString (java.lang.String,double)
location: class java.awt.Graphics
g.drawString(zhubajie.head+zhubajie.mouth+zhubajie.hand+zhubajie.foot+zhubajie.hand,5.10);
^
D:JAVAExample4_4.java:40: cannot resolve symbol
symbol : method drawString (java.lang.String,double)
location: class java.awt.Graphics
g.drawString(sunwukong.head+sunwukong.mouth+sunwukong.hand+sunwukong.foot+sunwukong.hand,5.70);
^
2 errors
请问怎么回事啊????
|
method drawString (java.lang.String,double)
这个方法在java.awt.Graphics中根本就没有。
不出错才怪,是不是把5,10写成了5.10?
这个方法在java.awt.Graphics中根本就没有。
不出错才怪,是不是把5,10写成了5.10?
|
drawString(AttributedCharacterIterator iterator, int x, int y)drawString(String str, int x, int y)
只有这两种方法! 你的参数搞错了!
具体看文档!
只有这两种方法! 你的参数搞错了!
具体看文档!