Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Please help me with the following code

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Thanked 0 Times in 0 Posts

    Default Please help me with the following code

    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() {
        private void initComponents() {
            btn = new JButton();
            setLayout(new GridBagLayout());
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent 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(); 
    	    tp.addTab("Tab2", TestLayerOne()); 
    	    tp.addTab("Tab3", TestLayerOne()); 
    	    setPreferredSize(new Dimension(1360,768));
    	    //   myFrame.setPreferredSize(new Dimension(1360,768)); 
    // 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() {
        private void initComponents() {
            lbl = new JLabel();
            setLayout(new GridBagLayout());
            lbl.setText("This is a Test ");
            add(lbl, new GridBagConstraints());
        private JLabel lbl;

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,445 Times in 2,396 Posts

    Default Re: Please help me with the following code

    Cross posted at Please help me with the following code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  2. Help merging program code with GUI code
    By Wilha in forum AWT / Java Swing
    Replies: 2
    Last Post: January 25th, 2012, 07:03 PM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM