Owl Teach Yourself Java 2 in 21 Days, Second Edition
HOME / ORDER THE BOOK / OTHER BOOKS / THANKS / PREVIOUS DAY / NEXT DAY

Day 10: Arranging Components on a User Interface

Notes and Corrections

  • None.

Source Files

Reader Questions

  • Question: I cannot understand how to make a card layout. Can you help? -- M.C.
    Answer:
    An example project should make it clearer. The BurmaShave application (BurmaShave.java and BurmaShave.class) displays a frame that uses card layout to display six different cards.
       The project uses an array of six JLabel objects to serve as each of the cards. These cards are titled Card 0, Card 1, Card 2, Card 3, Card 4, and Card 5, respectively.
       Each card is added to the frame's content pane by calling the pane's add(String, Container) method. The String is the name of the card, and the Container object is the container (or component) that will serve as the card.
       To show a card, the CardLayout object's show(Object, String) method is called. This method takes two arguments: the container that holds all the cards and the title of the card to display.
       When you're using cards in a frame, window or applet window, the parent component of those cards is the content pane of the container. In the BurmaShave example, the frame's content pane holds the cards.
       In order to display each of the cards, this application uses some concepts you'll be introduced to fully during Day 13, "Threads and Animation."

Activities

HOME / ORDER THE BOOK / OTHER BOOKS / THANKS / PREVIOUS DAY / NEXT DAY

Workbench | Books | RSS Feed | RSS Spec | Copyright 2024 World Readable