我有类画这样的矩形和线条
class MyCanvas extends JComponent {
int a,b,c,d;
String control;
public void setProps(int a, int b,int c,int d,String control) {
this.a=a; this.b=b; this.c=c; this.d=d; this.control=control;
repaint();//mark this component to be repainted
}
public void paint(Graphics g) {
super.paint(g);
if(control.equals("rect")){
g.setColor(Color.BLUE);
g.drawRect(a, b, c, d);
}else if(control.equals("line")){
g.drawLine(a, b, c, d);
}
}
}
public class drawShape {
public drawShape(int aa,int bb,int cc,int dd,String oo){
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
window.setBounds(30, 30, 500, 500);
MyCanvas canvas=new MyCanvas();
canvas.setProps(aa,bb,cc,dd,oo);
window.getContentPane().add(canvas);
window.setVisible(true);
}
}
我是我的另一课,我打电话
drawShape d1 = new drawShape(keepvar1,keepvar2,keepvar3,keepvar4,"line");
它创建新帧每次调用我想在同一帧中创建rectagle或行
我应该怎么做