// www.ShaneReustle.com - panels in javaimport java.awt.*;import java.applet.Applet;import java.awt.event.*;public class shane extends Applet implements ActionListener { Panel cardPanel, panLogin, panCreate; //Main Panel, Sub Panel 1, Sub Panel 2 CardLayout ourLayout; //The card layout object Button btnSubmitLogin, btnCreateAccount; //The buttons being used on the login panel public void init(){ ourLayout = new CardLayout(); //Defines the type of layout to use. cardPanel = new Panel(); //Create cardPanel which is the panel that will contain the other panels cardPanel.setLayout(ourLayout); //Set cardPanel's layout to be our Card Layout panLogin = new Panel(); //Create the login panel object panCreate = new Panel(); //Create the create panel object this.setLayout(new BorderLayout()); //Make setLayout for applet to be BorderLayout this.add(cardPanel, BorderLayout.CENTER); //Put the main container panel in the center cardPanel.add(panLogin, "panLogin"); //Adds the login sub panel to the main panel. 1) the object , 2) the identifyer cardPanel.add(panCreate, "panCreate"); //Adds the create sub panel to the main panel. 1) the object , 2) the identifyer cardPanel.setBackground(Color.red); //Make the main container panel have a RED background panLogin.setBackground(Color.blue); //Make the login panel have a BLUE background panCreate.setBackground(Color.green); //Make the create panel have a GREEN background Button btnSubmitLogin = new Button("Login"); //Create the login button object panLogin.add(btnSubmitLogin); //Add the login button to the login panel ourLayout.show(cardPanel, "panLogin"); } public void paint(Graphics g){ // Paint a pretty picture! } public void actionPerformed(ActionEvent e){ // Check for button clicks! }}