I have this these classes;
public class Car extends JComponent {
}
public class Mazda extends Car {
}
public class Subaru extends Car {
}
In my car class I override the method paint component
@Override
public void paintComponent(Graphics g) {
//why my planets aren't painted by this method
if (this instanceof Mazda) {
g.fillOval(0, 0, this.getWidth(), this.getHeight());
System.out.println(this.getClass());
}
if (this instanceof Subaru) {
g.setColor(Color.blue);
g.fillOval(0, 0, this.getWidth(), this.getHeight());
System.out.println(this.getClass());
}
}
It draws the instance of mazda just fine, but the code for instances of subaru just never gets called. It seems that subaru is not inheriting Jcomponent from Car? or why is not calling the painComponent? New to Java so I'm probably missing something basic