can anyone help me please with this problem. When I click on the button in the layerOne Class it creates TestLayerTwo () Below is my TestLayerOne Class where I have TestLayertwo () created under "btnActionPerformed". what I should do there so that LayerTwo shows up.
// TestLayerOne Class package test.gui; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class TestLayerOne extends JPanel { TestLayerTwo layerTwo; private JButton btn; public TestLayerOne() { initComponents(); } private void initComponents() { btn = new JButton(); setLayout(new GridBagLayout()); btn.setText("Button"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnActionPerformed(evt); } }); add(btn, new java.awt.GridBagConstraints()); } private void btnActionPerformed(ActionEvent evt) { // layerTwo layerTwo = new TestLayerTwo (); System.out.println("This is a Test"); } } // TabPanels Class package test.gui; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; public class TabPanels extends JFrame{ JFrame myFrame = null; // main to run and test this part of the program /* public static void main(String [] args) { new TabPanels(); } */ public TabPanels() { JTabbedPane tp = new JTabbedPane(); add(tp); tp.addTab("Tab1",TestLayerOne() tp.addTab("Tab2", TestLayerOne()); tp.addTab("Tab3", TestLayerOne()); setPreferredSize(new Dimension(1360,768)); // myFrame.setPreferredSize(new Dimension(1360,768)); pack(); setVisible(true); } } // layerTwoClass package test.gui; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JLabel; import javax.swing.JPanel; public class TestLayerTwo extends JPanel { /** * Creates new form TestLayerTwo */ public TestLayerTwo() { initComponents(); } private void initComponents() { lbl = new JLabel(); setLayout(new GridBagLayout()); lbl.setText("This is a Test "); add(lbl, new GridBagConstraints()); } private JLabel lbl; }