For- Number 2- You can remove all the buttons from the panel (If the panel contains only buttons, you can remove all the components from the panel) and then add the buttons- You are looping through each FAQ and adding the corresponding button?
For Number-3- If you want to access the FAQ Class- You can create a Custom Action listener which Implements ActionListener. Along with that you can have the reference to the current FAQ Class for which the instance of this was created and you can access in the ActionPerformed.
Yes, I do see one problem and have a few suggestions:
1) Your MyDrawPanel class's paintComponent method should probably not have that fillRect method call but instead should have a call to super.paintComponent(g). This will allow the underlying JPanel code to repaint itself and erase any previously rendered images.
2) If you are going to want your geometric images to look nice, in the paintCompnent method create a Graphics2D object by casting the Graphics object to Graphics2D and then call setRenderingHints(...) to turn on anti-aliasing. The constants to use for this are in the RenderingHints API, and the method definition is in the Graphics2D API. This will smooth out the "jaggies" in your oval.
3) I avoid calling setSize(...) or doing anything that sets absolute size or position of a JFrame or component. Rather, consider using setPreferredSize and call pack on the JFrame before setting it visible. I usually call pack, then setLocationRelativeTo(null), then setVisible(true)
Yep, you are trying to call the method from the class when you should be trying to call the method from an object of the class. And in fact, your TwoButtons class needs to have a MyDrawPanel variable that is initialized, displayed in the GUI, and used in the actionPerformed method for the method call that we're talking about.
No you didn't. You made a static variable which you shouldn't do as it is also forcing you to make the changeColor method static. Do you understand why it is important for these to be true instance variables? For one thing, there's no "this" in a static method, so there's no way you can tell the JPanel to repaint from within the method as I have suggested.
...but a basic OOPs programming issue.
Suhrid Karthik: Alternatively you could use a flag variable to indicate that the panel must be repainted only when the user clicks on the change color button.
pete stein: The problem as I see it is with the code you're not showing us. I have a feeling that your MyDrawPanel component changes a circle's color whenever it is redrawn -- possibly whenever it's paintComponent method is called, and by changing the size of the JLabel, you're making the JFrame and its components repaint themselves. The solution is not to change color in paintComponent as you do not have full control on when this is called, but rather elsewhere. Give your MyDrawPanel a public method called changeColor() where it changes the color of the circle and then call repaint() on the MyDrawPanel.