为什么我的drawString方法没有画出字符串来啊
publicvoidpaint(Graphicsg){intx0=this.x0;intx1=this.x1;inty0=this.y0;inty1=this.y1;fl...
public void paint(Graphics g) {
int x0=this.x0;
int x1=this.x1;
int y0=this.y0;
int y1=this.y1;
float x, y, dx, dy, e, temp; int s1,s2, interchange;
x = x0; y = y0 ;
dx = Math.abs(x1-x0); dy = Math.abs(y1- y0);
if(x1-x0>0)
s1=-1;
else if(x1-x0==0)
s1=0;
else
s1=1;
if(y1-y0>0)
s2=-1;
else if(y1-y0==0)
s2=0;
else
s2=1;
if (dy > dx){
temp = dx; dx = dy; dy = temp; interchange = 1;}
else interchange = 0;
e = 2*dy-dx;
for (int i = 1; i <= (int)dx; i++){
g.drawString("abcaaaaaaa",(int)x,(int)y );
g.setColor(Color.BLACK);
if (e > 0){
if (interchange == 1) x = x + s1; else y = y + s2;
e = e-2*dx;}
if (interchange == 1) y = y + s2; else x = x + s1;
e = e + 2*dy;
}
} 展开
int x0=this.x0;
int x1=this.x1;
int y0=this.y0;
int y1=this.y1;
float x, y, dx, dy, e, temp; int s1,s2, interchange;
x = x0; y = y0 ;
dx = Math.abs(x1-x0); dy = Math.abs(y1- y0);
if(x1-x0>0)
s1=-1;
else if(x1-x0==0)
s1=0;
else
s1=1;
if(y1-y0>0)
s2=-1;
else if(y1-y0==0)
s2=0;
else
s2=1;
if (dy > dx){
temp = dx; dx = dy; dy = temp; interchange = 1;}
else interchange = 0;
e = 2*dy-dx;
for (int i = 1; i <= (int)dx; i++){
g.drawString("abcaaaaaaa",(int)x,(int)y );
g.setColor(Color.BLACK);
if (e > 0){
if (interchange == 1) x = x + s1; else y = y + s2;
e = e-2*dx;}
if (interchange == 1) y = y + s2; else x = x + s1;
e = e + 2*dy;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询