I have a program in which a JPanel is added to a JFrame:
public class Test{ Test2 test = new Test2(); JFrame frame = new JFrame(); Test(){ ...
Your Test2 class is not a Component, it has a Component which is a difference.
Test2
Component
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)
JPanel