主题:麻烦帮我看看这个问题
import java.awt.*;
import java.applet.Applet;
public class ClassDemo extends Applet
{ MyOval oval1=new MyOval( );
MyOval oval2=new MyOval(180,30,50,80);
public void paint(Graphics g)
{ oval1.setPosition(30,30);
oval1.setSize(50,80);
oval1.draw(g);
[color=0000FF] g.drawString("oval1 x Position:"+oval1.getX(),+oval1.getX(),oval1.getY()+100);color]
g.drawString("oval1 Y Position:"+oval1.getY(),+oval1.getX(),oval1.getY()+130);
oval2.draw(g);
g.drawString("Oval2 X Position:"+oval2.getX(),oval2.getX()-30,oval2.getY()+100);
g.drawString("Oval2 Y Position:"+oval2.getY(),oval2.getX()-30,oval2.getY()+130);
}
}
class MyOval
{ private int x,y,width,height;
MyOval( )
{ x=0;
y=0;
width=0;
height=0;
}
MyOval(int xPos,int yPos,int w,int h)
{ x=xPos;
y=yPos;
width=w;
height=h;
}
public void setPosition(int xPos,int yPos)
{ x=xPos;
y=yPos;
}
public void setSize(int w,int h)
{ width=w;
height=h;
}
public int getX( )
{ return x;
}
public int getY( )
{ return y;
}
public void draw(Graphics g)
{ g.setColor(Color.red);
g.fillOval(x,y,width,height);
}
}
为什么有两个相同的+oval1.getY(),+oval1.getX() 而且我把其中的一个注释以后就会报错 请问是为什么 再请问一下这行语句是什么意思
import java.applet.Applet;
public class ClassDemo extends Applet
{ MyOval oval1=new MyOval( );
MyOval oval2=new MyOval(180,30,50,80);
public void paint(Graphics g)
{ oval1.setPosition(30,30);
oval1.setSize(50,80);
oval1.draw(g);
[color=0000FF] g.drawString("oval1 x Position:"+oval1.getX(),+oval1.getX(),oval1.getY()+100);color]
g.drawString("oval1 Y Position:"+oval1.getY(),+oval1.getX(),oval1.getY()+130);
oval2.draw(g);
g.drawString("Oval2 X Position:"+oval2.getX(),oval2.getX()-30,oval2.getY()+100);
g.drawString("Oval2 Y Position:"+oval2.getY(),oval2.getX()-30,oval2.getY()+130);
}
}
class MyOval
{ private int x,y,width,height;
MyOval( )
{ x=0;
y=0;
width=0;
height=0;
}
MyOval(int xPos,int yPos,int w,int h)
{ x=xPos;
y=yPos;
width=w;
height=h;
}
public void setPosition(int xPos,int yPos)
{ x=xPos;
y=yPos;
}
public void setSize(int w,int h)
{ width=w;
height=h;
}
public int getX( )
{ return x;
}
public int getY( )
{ return y;
}
public void draw(Graphics g)
{ g.setColor(Color.red);
g.fillOval(x,y,width,height);
}
}
为什么有两个相同的+oval1.getY(),+oval1.getX() 而且我把其中的一个注释以后就会报错 请问是为什么 再请问一下这行语句是什么意思