3 回答
TA贡献1780条经验 获得超1个赞
如果您需要的是圆形中框架的宽度和高度,为什么不将DrawFrame的宽度和高度传递给DrawCircle构造函数:
public DrawCircle(int w, int h){
this.w = w;
this.h = h;
diBig = 300;
diSmall = 10;
maxRad = (diBig/2) - diSmall;
xSq = 50;
ySq = 50;
xPoint = 200;
yPoint = 200;
}
您还可以向DrawCircle添加一些新方法:
public void setWidth(int w)
this.w = w;
public void setHeight(int h)
this.h = h;
甚至:
public void setDimension(Dimension d) {
w=d.width;
h=d.height;
}
如果沿着这条路线走,则需要更新DrawFrame来制作DrawCircle的本地变量,以在这些变量上调用这些方法。
编辑:
如我的文章顶部所述,在更改DrawCircle构造函数时,请不要忘记在DrawFrame的构造函数调用中添加宽度和高度:
public class DrawFrame extends JFrame {
public DrawFrame() {
int width = 400;
int height = 400;
setTitle("Frame");
setSize(width, height);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
//pass in the width and height to the DrawCircle contstructor
contentPane.add(new DrawCircle(width, height));
}
}
添加回答
举报