KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Panel


1 /*
2  * @(#)Panel.java 1.35 04/03/01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 import java.awt.peer.PanelPeer;
10 import javax.accessibility.*;
11
12 /**
13  * <code>Panel</code> is the simplest container class. A panel
14  * provides space in which an application can attach any other
15  * component, including other panels.
16  * <p>
17  * The default layout manager for a panel is the
18  * <code>FlowLayout</code> layout manager.
19  *
20  * @version 1.35, 03/01/04
21  * @author Sami Shaio
22  * @see java.awt.FlowLayout
23  * @since JDK1.0
24  */

25 public class Panel extends Container JavaDoc implements Accessible {
26     private static final String JavaDoc base = "panel";
27     private static int nameCounter = 0;
28
29     /*
30      * JDK 1.1 serialVersionUID
31      */

32      private static final long serialVersionUID = -2728009084054400034L;
33
34     /**
35      * Creates a new panel using the default layout manager.
36      * The default layout manager for all panels is the
37      * <code>FlowLayout</code> class.
38      */

39     public Panel() {
40     this(new FlowLayout JavaDoc());
41     }
42
43     /**
44      * Creates a new panel with the specified layout manager.
45      * @param layout the layout manager for this panel.
46      * @since JDK1.1
47      */

48     public Panel(LayoutManager JavaDoc layout) {
49     setLayout(layout);
50     }
51
52     /**
53      * Construct a name for this component. Called by getName() when the
54      * name is null.
55      */

56     String JavaDoc constructComponentName() {
57         synchronized (getClass()) {
58         return base + nameCounter++;
59     }
60     }
61
62     /**
63      * Creates the Panel's peer. The peer allows you to modify the
64      * appearance of the panel without changing its functionality.
65      */

66
67     public void addNotify() {
68         synchronized (getTreeLock()) {
69         if (peer == null)
70             peer = getToolkit().createPanel(this);
71         super.addNotify();
72     }
73     }
74
75 /////////////////
76
// Accessibility support
77
////////////////
78

79     /**
80      * Gets the AccessibleContext associated with this Panel.
81      * For panels, the AccessibleContext takes the form of an
82      * AccessibleAWTPanel.
83      * A new AccessibleAWTPanel instance is created if necessary.
84      *
85      * @return an AccessibleAWTPanel that serves as the
86      * AccessibleContext of this Panel
87      */

88     public AccessibleContext getAccessibleContext() {
89         if (accessibleContext == null) {
90             accessibleContext = new AccessibleAWTPanel();
91         }
92         return accessibleContext;
93     }
94
95     /**
96      * This class implements accessibility support for the
97      * <code>Panel</code> class. It provides an implementation of the
98      * Java Accessibility API appropriate to panel user-interface elements.
99      */

100     protected class AccessibleAWTPanel extends AccessibleAWTContainer {
101
102         private static final long serialVersionUID = -6409552226660031050L;
103
104         /**
105          * Get the role of this object.
106          *
107          * @return an instance of AccessibleRole describing the role of the
108          * object
109          */

110         public AccessibleRole getAccessibleRole() {
111             return AccessibleRole.PANEL;
112         }
113     }
114
115 }
116
Popular Tags