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 6862389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:21+00:00 2026-05-27T02:39:21+00:00

So I’m working on a research assignment with a gui and I have 3

  • 0

So I’m working on a research assignment with a gui and I have 3 boxes on the left panel “Input”, “Processing”, and “Display”, if “Input” is selected using CardLayout then the first panel is shown on the right, if “Display” is selected then the last panel is displayed, but I can’t get “Processing” to display in this part:

public void actionPerformed( ActionEvent event )   {
    // show first card
    if ( event.getSource() == controls[ 0 ] )    
        cardManager.first( deck ); 

    else if ( event.getSource() == controls[ 1 ] )    
        cardManager.show( card2Panel(), "c2");  
    // show previous card
    else if ( event.getSource() == controls[ 2 ] )
        cardManager.last( deck );

The code in it’s enitre form:

import java.awt.*;

import java.awt.event.;
import javax.swing.
;

public class BookCentre extends JFrame implements ActionListener {

private CardLayout cardManager;
private JPanel deck;
private JButton controls[];
private String names[] = { "Input", "Processing", "Display"};

public BookCentre(){
    super( "CardLayout" );
    Container container = getContentPane();
    deck = new JPanel();
    cardManager = new CardLayout(); 
    deck.setLayout( cardManager );  
    deck.add( card1Panel(), "c1" );
    deck.add( card2Panel(), "c2" );
    deck.add( card3Panel(), "c3" );
    JPanel buttons = new JPanel();
    buttons.setLayout( new GridLayout( 2, 2 ) );
    controls = new JButton[ names.length ];
    for ( int count = 0; count < controls.length; count++ ) {
        controls[ count ] = new JButton( names[ count ] );
        controls[ count ].addActionListener( this );
        buttons.add( controls[ count ] );
        container.add( buttons, BorderLayout.WEST );
        container.add( deck, BorderLayout.EAST );
        setSize( 450, 200 );
        setVisible( true );}

}

public JPanel card1Panel(){ 
JLabel label1 = new JLabel( "card one",  SwingConstants.CENTER );
JPanel card1 = new JPanel();
card1.add( label1 ); 
return card1;

}

public JPanel card2Panel(){
    JLabel label2 = new JLabel( "card two", SwingConstants.CENTER );
    JPanel card2 = new JPanel();
    card2.setBackground( Color.yellow );
    card2.add( label2 );
    return card2;

}

public JPanel card3Panel(){
    JLabel label3 = new JLabel( "card three" );
    JPanel card3 = new JPanel();
    card3.setLayout( new BorderLayout() );  
    card3.add( new JButton( "North" ), BorderLayout.NORTH);
    card3.add( new JButton( "West" ), BorderLayout.WEST );
    card3.add( new JButton( "East" ), BorderLayout.EAST );
    card3.add( new JButton( "South" ), BorderLayout.SOUTH);
    card3.add( label3, BorderLayout.CENTER );
    return card3;

}

public void actionPerformed( ActionEvent event )   {
    // show first card
    if ( event.getSource() == controls[ 0 ] )    
        cardManager.first( deck ); 

    else if ( event.getSource() == controls[ 1 ] )    
        cardManager.show( card2Panel(), "c2");  
    // show previous card
    else if ( event.getSource() == controls[ 2 ] )
        cardManager.last( deck );           

}

public static void main( String args[] )   {
    BookCentre cardDeckDemo = new BookCentre();
    cardDeckDemo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );

}
}

in public void ActionPerformed I was able to use cardManager.first, next, previous, last. I only want the “Processing” panel to be displayed though (so card2), not the user seeing first, last or cycling through all panels.

  • 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-05-27T02:39:21+00:00Added an answer on May 27, 2026 at 2:39 am

    Check out the Java Trail for CardLayout. The cardManager.show() call in the ActionListener should be

    cardManager.show( deck, "c2" );

    as the first parameter is the parent container with a CardLayout, not the component that you want to display.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.