panels

panels - CSc 2700: Lecture # 9 Panels September 25, 2008 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 2700: Lecture # 9 Panels September 25, 2008 1 Creating Panels Very often Swing applications do not add components directly to a frame. Components are usually grouped together and placed in panels. A panel is an invisible container used for arranging components. A panel can have a layout manager. Components are placed in panels and the panels are then added to a frame. One panel may hold a group of buttons and another a group of checkboxes. Placing related components in a panel can add greater Fexibility to frame design. ±or example, you might place ²ve buttons in one panel using a Fow layout manager, and in a second panel, you might arrange four textboxes using a grid layout manager. Now, you can place these two panels or groups of components in a frame using the BorderLayout manager. Swing’s JPanel class extends JComponent. Two constructors of JPanel are: JPanel() instantiates a JPanel object with ±lowLayout as the default layout manager. JPanel (LayoutManager layoutManager) instantiates a JPanel object with the speci²ed layout manager. The setLayout() method is also available for JPanels. A label is used to display some text or an image. The Swing component that encapsulates a label is JLabel. The di³erence between a label and a button is that a button is used for input while a label is not. You can instantiate JLabel with the constructor JLabel(String text) . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
How Good Is Your Memory? The game How Good Is Your Memory? (also known as Concentration or Memory) utilizes a frame with twenty numbered buttons. Each button hides a picture. There are ten diFerent pictures and two diFerent buttons hide the same picture. ±or example, there may be a smiley face hidden by both buttons 6 and 19 and question marks hidden by buttons 2 and 16. See ±igure 1. The game is played by two persons. Alternately, players click two buttons ±igure 1: Concentration Game and the buttons’ hidden pictures are displayed. If the pictures match, the player gets a point and the pictures remain visible. If the pictures do not match, they are hidden again by the buttons. When all matches have been revealed, the player with the larger number of points wins The frame also shows each player’s score. On the bottom of the frame are four buttons. The ”Close” button hides the last two pictures displayed. The ”Open ” button displays the pictures behind the last two buttons clicked. The ”Reset” button initializes a game.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/06/2009 for the course CSC 2700 taught by Professor Duncan during the Spring '08 term at LSU.

Page1 / 9

panels - CSc 2700: Lecture # 9 Panels September 25, 2008 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online