Your Test2
class is not a Component
, it has a Component
which is a difference.
Either you do something like
frame.add(test.getPanel() );
after you introduced a getter for the panel in your class, or you make sure your Test2
class becomes a Component
(e.g. by extending a JPanel
)