You would need to move your PlottingPanel variable out of the constructor and up to class level. You can add a method like setPlot() to PlottingPanel to indicate which function is to be drawn and your painting method will need reference whatever info you set to know which function to draw. Your button handlers will call plottingPanel.setPlot() to change the type.
On a side note, you should override paintComponent() instead of paint() in your panel class.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Yes, you need to add some method by which your buttons can set which plot should be shown. For the plotting itself, you could create a Plot interface with a draw(Graphics) method that would draw the plot onto the supplied Graphics context and create small plot classes for each of the function types.
If that's too complex, you could also just use an Enum for the plot type and have branches for each type in your paintComponent().
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847