Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:17:19+00:00 2026-06-13T10:17:19+00:00

here is the question. I have a JApplet, and inside the applet I have

  • 0

here is the question. I have a JApplet, and inside the applet I have two JPanels, panel1 and panel2. Each panel has a label shown “panel1” or “panel2”, and each panel has a button called “switch”. When I run the applet, I only want panel1 to be visible. And when I click the switch button, I wanna panel1 to be invisible (or disappear) and panel2 to be visible. I will also want to click the switch button in panel2 to switch back to panel1. Can anyone help me with this?

public class MyApplet extends JApplet
{
    private Panel1 panel1;
    private Panel2 panel2;

    public void init()
    {
        setLayout(new FlowLayout());

        panel1 = new Panel1();
        panel2 = new Panel2();

        add(panel1);
        //add(panel2);
    }
}

public class Panel1 extends JPanel
{
    private JLabel label;
    private JButton button;

    public Panel1()
    {
        setLayout(new FlowLayout());

        label = new JLabel("Panel1");
        button = new JButton("Switch1");

        add(label);
        add(button);
    }
}

public class Panel2 extends JPanel
{
    private JLabel label;
    private JButton button;

    public Panel2()
    {
        setLayout(new FlowLayout());

        label = new JLabel("Panel2");
        button = new JButton("Switch2");

        add(label);
        add(button);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:17:20+00:00Added an answer on June 13, 2026 at 10:17 am

    Add a “content” to the applet, where you want to switch panels in and out off.

    Set this panels layout manager to CardLayout

    Add your other panels to the “content” pane

    content.add(aPanel, "PanelA");
    content.add(bPanel, "PanelB");
    

    Use the CardLayout API to switch the panels…

    cardLayout.show(content, "PanelB");
    

    Have a read through How to Use CardLayout for more details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basic powershell question here - I have two computers in the c:\temp\servers.txt file and
Here is my question : I have a huge class (HugeClass) and I wanted
Newbee question here - I have this method in the view controller m: -(void)
here's my question: I have a table TRUST(id INT, trustlevel INT) which contains records
Basic question here - I have many lines of code that look something like:
here's my question: I have an MVC3 C# application and I need to update
I have a question here regarding iPhone app submission. I have a free application
The question I have here is for some reason when the getInboxUnreadMessagesCount js function
Here is a question that I have had for some time but never actually
here is a good question: I have an application compiled for iPhone OS 2.21.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.