I
Ian Stanley
Hi,
I have a program which adds shapes (rectangles, circles, etc) to a vector v.
this is done by:
v.add(new Rects(x, y, w, h)) ;
Is there a easier way to make the Rects class have all the charateristics of
a 2D Rectangle?(such as methods like contains etc) while keeping the
inheritance structure
effectively the same as v.add(new 2DRects(x, y, w, h)) ;
Any pointers appreciated
regards
Ian
the present way a rectangle is created is:
class shape extends JComponent {
int x, y ;
int w, h ;
shape(int x, int y, int w, int h) {
super() ;
this.x = x ;
this.y = y ;
this.w = w ;
this.h = h ;
}
class Rects extends shape {
Rects(int x, int y, int w, int h) {
super(x, y, w, h) ;
}
public void paint(Graphics g) {
g.drawRect(x, y, w, h) ;
}
}
I have a program which adds shapes (rectangles, circles, etc) to a vector v.
this is done by:
v.add(new Rects(x, y, w, h)) ;
Is there a easier way to make the Rects class have all the charateristics of
a 2D Rectangle?(such as methods like contains etc) while keeping the
inheritance structure
effectively the same as v.add(new 2DRects(x, y, w, h)) ;
Any pointers appreciated
regards
Ian
the present way a rectangle is created is:
class shape extends JComponent {
int x, y ;
int w, h ;
shape(int x, int y, int w, int h) {
super() ;
this.x = x ;
this.y = y ;
this.w = w ;
this.h = h ;
}
class Rects extends shape {
Rects(int x, int y, int w, int h) {
super(x, y, w, h) ;
}
public void paint(Graphics g) {
g.drawRect(x, y, w, h) ;
}
}