CardLayout

This might be a sort of newbie question, but I cannot figure out the answer.

I am using a CardLayout on a class called GamePanel which extends JPanel. I set the layout of this Panel to a CardLayout object. And I added three classes that extend JPanel to GamePanel: InfoPanel, HelpPanel and OptionsPanel. How do I get my buttonListeners on InfoPanel to switch the CardLayout so that it goes to HelpPanel next?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

import java.io.*;

import javax.swing.JOptionPane;

// This class is what the Applet adds, it has a Card Layout, and manages the different pages,

// which will be defined as JPanels.

publicclass GameFrameextends JPanel

{

//Instantiate Layout/Panels

private CardLayout cardLayout;

private OptionsPanel optionsPanel;

private GamePanel gamePanel;

private HelpPanel helpPanel;

private IntroPanel introPanel;

public GameFrame()

{

//initialize the card layout

cardLayout =new CardLayout();

//set the layout of the Frame

setLayout(cardLayout);

//initialize all of the panels

optionsPanel =new OptionsPanel();

gamePanel =new GamePanel();

helpPanel =new HelpPanel();

introPanel =new IntroPanel(cardLayout, optionsPanel, gamePanel, helpPanel);

//add all of the panels to the cardLayout

add(introPanel,"IntroPanel");

add(optionsPanel,"OptionsPanel");

add(gamePanel,"GamePanel");

add(helpPanel,"HelpPanel");

//set Frame to show IntroPanel

}

}

any help would be appreciated, thanks.

[2828 byte] By [kory.kirka] at [2007-10-3 8:44:22]
# 1

by far the easiest and quickest way to find a solution is to search the forums

"new CardLayout"

as a search term would generally get you numerous examples of sample code,

which you should be able to follow how it is done.

the tutorial is another spot with working sample code

http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html

Michael_Dunna at 2007-7-15 3:53:09 > top of Java-index,Desktop,Core GUI APIs...