I'm having difficulty correctly changing a custom component on a JFrame while the program that displays this is running.
My situation can be described as follow:
I have a global variable which of type CellularAutomaton<Cell>.
This class is a generic abstract class that extends JComponent with a implemented paintComponent( ) function that uses a abstract method drawShape() to draw a single cell in a cellular automaton.
Firstly I assign this gloabal variable to some subclass that implements the above mentioned class and then add it to a JFrame which is then displayed.
The problem is that when a certain button is triggered I want to display a new componet instead of the above mentioned component. This new component also extends the same abstract class as the old one.
I do this by assigning the golbal variable to the desired component, but then the JFrame that contains this, does not repaint it, no matter what.
All the above mentioned components' paintComponent( ) functions works correctly, but as soon as I make that assignment the JFrame no longer repaints that component.
public class Main {
...
CellularAutomaton<Cell>ca; //the global variable mentioned above
...
public Main() {
...
JFrame frame = ...
ca = someCA;
frame.add(ca) //works fine if ca remains the same
frame.setVisible(true);
...
}
//the actionListener for when the above mentioned button
class DisplayHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
ca=someOtherCA;
ca.repaint(); //does nothing after assingment
}
}
Any help would be much appreciated considering this project must be in by tommorow, sigh.