Source Code Cross Referenced for Label.java in  » 6.0-JDK-Modules » j2me » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)Label.java	1.42 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         *
026:         */
027:        package java.awt;
028:
029:        import sun.awt.peer.LabelPeer;
030:        import sun.awt.PeerBasedToolkit;
031:
032:        /**
033:         * A <code>Label</code> object is a component for placing text in a
034:         * container. A label displays a single line of read-only text.
035:         * The text can be changed by the application, but a user cannot edit it
036:         * directly.
037:         * <p>
038:         * For example, the code&nbsp;.&nbsp;.&nbsp;.
039:         * <p>
040:         * <hr><blockquote><pre>
041:         * setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
042:         * add(new Label("Hi There!"));
043:         * add(new Label("Another Label"));
044:         * </pre></blockquote><hr>
045:         * <p>
046:         * produces the following label:
047:         * <p>
048:         * <img src="images-awt/Label-1.gif"
049:         * ALIGN=center HSPACE=10 VSPACE=7>
050:         *
051:         * @version	1.31, 07/01/98
052:         * @author 	Sami Shaio
053:         * @since       JDK1.0
054:         */
055:        public class Label extends Component {
056:            /**
057:             * Indicates that the label should be left justified.
058:             * @since   JDK1.0
059:             */
060:            public static final int LEFT = 0;
061:            /**
062:             * Indicates that the label should be centered.
063:             * @since   JDK1.0
064:             */
065:            public static final int CENTER = 1;
066:            /**
067:             * Indicates that the label should be right justified.
068:             * @since   JDK1.0t.
069:             */
070:            public static final int RIGHT = 2;
071:            /**
072:             * The text of this label.
073:             */
074:            String text;
075:            /**
076:             * The label's alignment.  The default alignment is set
077:             * to be left justified.
078:             */
079:            int alignment = LEFT;
080:            private static final String base = "label";
081:            private static int nameCounter = 0;
082:            /*
083:             * JDK 1.1 serialVersionUID
084:             */
085:            private static final long serialVersionUID = 3094126758329070636L;
086:
087:            /**
088:             * Constructs an empty label.
089:             * @since JDK1.0
090:             */
091:            public Label() {
092:                this ("", LEFT);
093:            }
094:
095:            /**
096:             * Constructs a new label with the specified string of text,
097:             * left justified.
098:             * @param text the string that the label presents.
099:             * @since JDK1.0
100:             */
101:            public Label(String text) {
102:                this (text, LEFT);
103:            }
104:
105:            /**
106:             * Constructs a new label that presents the specified string of
107:             * text with the specified alignment.
108:             * <p>
109:             * Possible values for <code>alignment</code> are <code>Label.LEFT</code>,
110:             * <code>Label.RIGHT</code>, and <code>Label.CENTER</code>.
111:             * @param     text        the string that the label presents.
112:             * @param     alignment   the alignment value.
113:             * @since     JDK1.0
114:             */
115:            public Label(String text, int alignment) {
116:                this .text = text;
117:                setAlignment(alignment);
118:            }
119:
120:            /**
121:             * Construct a name for this component.  Called by getName() when the
122:             * name is null.
123:             */
124:            String constructComponentName() {
125:                return base + nameCounter++;
126:            }
127:
128:            /**
129:             * Creates the peer for this label.  The peer allows us to
130:             * modify the appearance of the label without changing its
131:             * functionality.
132:             */
133:            public void addNotify() {
134:                synchronized (getTreeLock()) {
135:                    if (peer == null)
136:                        peer = ((PeerBasedToolkit) getToolkit())
137:                                .createLabel(this );
138:                    super .addNotify();
139:                }
140:            }
141:
142:            /**
143:             * Gets the current alignment of this label. Possible values are
144:             * <code>Label.LEFT</code>, <code>Label.RIGHT</code>, and
145:             * <code>Label.CENTER</code>.
146:             * @see        java.awt.Label#setAlignment
147:             * @since      JDK1.0
148:             */
149:            public int getAlignment() {
150:                return alignment;
151:            }
152:
153:            /**
154:             * Sets the alignment for this label to the specified alignment.
155:             * Possible values are <code>Label.LEFT</code>,
156:             * <code>Label.RIGHT</code>, and <code>Label.CENTER</code>.
157:             * @param      alignment    the alignment to be set.
158:             * @exception  IllegalArgumentException if an improper value for
159:             *                          <code>alignment</code> is given.
160:             * @see        java.awt.Label#getAlignment
161:             * @since      JDK1.0
162:             */
163:            public synchronized void setAlignment(int alignment) {
164:                switch (alignment) {
165:                case LEFT:
166:                case CENTER:
167:                case RIGHT:
168:                    this .alignment = alignment;
169:                    LabelPeer peer = (LabelPeer) this .peer;
170:                    if (peer != null) {
171:                        peer.setAlignment(alignment);
172:                    }
173:                    return;
174:                }
175:                throw new IllegalArgumentException("improper alignment: "
176:                        + alignment);
177:            }
178:
179:            /**
180:             * Gets the text of this label.
181:             * @return     the text of this label.
182:             * @see        java.awt.Label#setText
183:             * @since      JDK1.0
184:             */
185:            public String getText() {
186:                return text;
187:            }
188:
189:            /**
190:             * Sets the text for this label to the specified text.
191:             * @param      text the text that this label presents.
192:             * @see        java.awt.Label#getText
193:             * @since      JDK1.0
194:             */
195:            public synchronized void setText(String text) {
196:                if (text != this .text
197:                        && (this .text == null || !this .text.equals(text))) {
198:                    this .text = text;
199:                    LabelPeer peer = (LabelPeer) this .peer;
200:                    if (peer != null) {
201:                        peer.setText(text);
202:                    }
203:                }
204:            }
205:
206:            /**
207:             * Returns the parameter string representing the state of this
208:             * label. This string is useful for debugging.
209:             * @return     the parameter string of this label.
210:             * @since      JDK1.0
211:             */
212:            protected String paramString() {
213:                String str = ",align=";
214:                switch (alignment) {
215:                case LEFT:
216:                    str += "left";
217:                    break;
218:
219:                case CENTER:
220:                    str += "center";
221:                    break;
222:
223:                case RIGHT:
224:                    str += "right";
225:                    break;
226:                }
227:                return super .paramString() + str + ",text=" + text;
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.