struggling with creating a GUI
I'm not quite sure where to put this topic in, I hope this is the right category.
I'm creating a simple music player with a JFrame and two JPanels
I put the three components into three classes:
a PlayerFrame extends JFrame,
a SongInfoPanel extends JPanel,
and a ControllerPanel extens JPanel.
The SongInfoPanel contains labels that show information about the song, and a label that indicates whether the music is playing or paused.
The ControllerPanel contains buttons used to pause and play the music.
And I have another Main class that does not extends anything, it creates a PlayerFrame, a SongInfoPanel, and a ControllerPanel separately. The Main class then adds the two panels into the PlayerFrame.
Now here's my confusion. I press the play/pause button but also want also the label in SongInfoPanel to be updated... These two objects don't know that each other exists, how could the SongInfoPanel be updated when a button in ControllerPanel is pressed?
I've thought of several ways to do it, but i'm not sure which one would be appropriate, or none at all (which i think is very likely so)...
1. When creating a ControllerPanel, pass a reference to SongInfoPanel as an argument so the ControllerPanel can update the SongInfoPanel directly. I have a feeling that this is the worst-in-the-world solution.
2. Make the two panels inner classes of PlayerFrame. Again, so that ControllerPanel can access a variable that points directly to SongInfoPanel. But I would end up having only one big outer class, this would be a bad bad design wouldn't it?
or 3. When a button in ControllerPanel is pressed, the button's actionlistener calls getParent().getParent()... so on until it reaches PlayerFrame. And create a method in the PlayerFrame that updates the SongInfoPanel. This would also mean that I need a method to alter play/pause label. Later on I would need the player to change the song, I would then need another method to update the labels for song info, and so on?
or what should be the way to handle this problem? I'm completely lost.
Sorry for the confusion I may have created. And thanks in advance for any help.