package ncut.zyf.hello;import java.awt.*;
import java.applet.*;
class dog{
String name;
int height;
int weight;
public dog(String Cname,int Cheight,int Cweight){
name=Cname;
height=Cheight;
weight=Cweight;}
public void ShowDog(Graphics g,int x,int y){
g.drawString("name:"+name,x,y);
g.drawString("height:"+height, x+20, y+20);
g.drawString("weight:"+weight, x+30, y+30);
}}public class myApplet extends Applet{
public void paint(Graphics g);{
dog dolly=new dog("Kelly dolly",100,23);
dog.ShowDog(g,23,23);}
}
我的源程序,是按照书打的。应该不会有错。然后错的地方它说是public void paint(Graphics g)缺少方法主体或生命对象。第二是dog.ShowDog(g,23,23)它说无法从上下文引用静态方法ShowDog(java.awt.Graphics,int ,int)
import java.applet.*;
class dog{
String name;
int height;
int weight;
public dog(String Cname,int Cheight,int Cweight){
name=Cname;
height=Cheight;
weight=Cweight;}
public void ShowDog(Graphics g,int x,int y){
g.drawString("name:"+name,x,y);
g.drawString("height:"+height, x+20, y+20);
g.drawString("weight:"+weight, x+30, y+30);
}}public class myApplet extends Applet{
public void paint(Graphics g);{
dog dolly=new dog("Kelly dolly",100,23);
dog.ShowDog(g,23,23);}
}
我的源程序,是按照书打的。应该不会有错。然后错的地方它说是public void paint(Graphics g)缺少方法主体或生命对象。第二是dog.ShowDog(g,23,23)它说无法从上下文引用静态方法ShowDog(java.awt.Graphics,int ,int)
多了;号正确的用法是:dolly. ShowDog(g,23,23);
多练习。。 我也是新手。 大家一起努力吧。