/* * ============================================================== * DemoCardLayout.java : Create card layout manager. This applet * .... * Card 1 : Software Company sites * JavaSoft, Sun, IBM, Boeing * Card 2 : Aerospace Company sites * NASA, Boeing, Lockheed, Northrop. * * Adapted from : Pantham S., Pure JFC Swing, 1999. * Modified by : Mark Austin March, 2001 * ============================================================== */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; public class DemoCardLayout extends JApplet { // 1. Declare some panel and button references. JPanel controlPanel; JPanel cardsPanel, swCompPanel, aeroCompPanel; JButton nextButton, previousButton; JButton javasoftButton, sunButton, ibmButton, netscapeButton; JButton nasaButton, boeingButton, lockheedButton, northropButton; URL currentSite = null; // 2. Define the string arrays for the sites and site urls. String[] swCompSites = { "JavaSoft", "Sun Microsystems", "IBM", "NetScape" }; String[] aeroCompSites = { "NASA", "Boeing", "Lockheed", "Northrop" }; String[] siteURLs = { "http://www.javasoft.com/", "http://www.sun.com/", "http://www.ibm.com/", "http://www.netscape.com/" }; Container container = null; public void init() { // 3. Get a handle on the applet's content pane. container = this.getContentPane(); // 4. Create a control panel object. controlPanel = new JPanel(); controlPanel.setLayout(new GridLayout(1,2,10,10)); // 5. Create and add the next and previous control buttons. ButtonListener listener = new ButtonListener(); nextButton = new JButton("Next Card"); nextButton.setActionCommand("Next Button"); nextButton.addActionListener(listener); controlPanel.add(nextButton); previousButton = new JButton("Previous Card"); previousButton.setEnabled(false); previousButton.setActionCommand("Previous Button"); previousButton.addActionListener(listener); controlPanel.add(previousButton); // 6. Create a panel to contain the cards. /* Each card will display a set of buttons to visit a specific Web site. */ cardsPanel = new JPanel(); cardsPanel.setLayout(new CardLayout()); swCompPanel = new JPanel(); aeroCompPanel = new JPanel(); swCompPanel.setLayout(new GridLayout(2,2,10,10)); aeroCompPanel.setLayout(new GridLayout(2,2,10,10)); // 7. Add buttons to the these cards. for (int i=0; i