You have two instances of TextPanel
, one in MainFrame
and the other one in FormPanel
. TextPanel
that is defined in FormPanel
is actually not added to the panel, so textPanel.setText("");
has no effect on it as it is not visible.
When the text appended with Add To Cart!
button it actually goes through a method in MainFrame
- formEventOccurred()
that executes textPanel.appendSomeText()
. This is the other instance of TextPanel
that is part of MainFrame
and that is actually visible.
Looks like you need to move the duplicated logic from the main frame to the panels. Usually you should not extend JFrame
as you are not adding any new functionality.