It sounds as if you're using inheritance incorrectly since the questions you ask are not solved through inheritance but rather through composition. For example, one way for a class to change the state of another is for the first class to hold a reference to the second class and have it call methods of the second class, and this is likely what you need to do. The details of a solution will depend on the details of your problem and your code.
You state:
what i was trying to do was use the paintCompontent method() in my own personal subclass but i couldn't extend the subclass with JPanel as the personal subclass has already been extended
You should do all your drawing within the JPanel's paintComponent period, and the JPanel is part of the view the visualized part of your program. But what is painted can depend on the state of other classes, in particular, the model, or the classes of your program that deal with program logic. I suggest that you separate your concerns along a M-V-C (model-view-controller) pattern to allow you to do just what you want -- allow state changes in the model be reflected in the view.
Again, for a more detailed answer, you're going to want to provide more detail about your problem and your code.
For a very (overly) simplistic example using your code:
// no need to extend JPanel....
public class Dog extends Animal {
// give Dog a drawing method
public void draw(Graphics2D g2) {
// .... some code to draw
}
}
public class DrawingPanel extends JPanel {
private Dog dog; // hold Dog reference
// allow passage of current Dog into class
public DrawingPanel(Dog dog) {
this.dog = dog;
}
@Override
protected void paintComponent(g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
dog.draw(g2); // draw Dog's picture
}
}
elsewhere:
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Dog myDog = new Dog();
DrawingPanel drawingPanel = new DrawingPanel(myDog);
JFrame myFrame = new JFrame("Dog Frame");
myFrame.add(drawingPanel);
//..... etc...
myFrame.setVisible(true);
});
}