home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- import java.awt.peer.LabelPeer;
-
- public class Label extends Component {
- public static final int LEFT = 0;
- public static final int CENTER = 1;
- public static final int RIGHT = 2;
- String label;
- int alignment;
-
- public Label() {
- this("");
- }
-
- public Label(String label) {
- this.label = label;
- }
-
- public Label(String label, int alignment) {
- this.label = label;
- this.setAlignment(alignment);
- }
-
- public synchronized void addNotify() {
- super.peer = ((Component)this).getToolkit().createLabel(this);
- super.addNotify();
- }
-
- public int getAlignment() {
- return this.alignment;
- }
-
- public void setAlignment(int alignment) {
- switch (alignment) {
- case 0:
- case 1:
- case 2:
- this.alignment = alignment;
- LabelPeer peer = (LabelPeer)super.peer;
- if (peer != null) {
- peer.setAlignment(alignment);
- }
-
- return;
- default:
- throw new IllegalArgumentException("improper alignment: " + alignment);
- }
- }
-
- public String getText() {
- return this.label;
- }
-
- public void setText(String label) {
- if (label != this.label && (this.label == null || !this.label.equals(label))) {
- this.label = label;
- LabelPeer peer = (LabelPeer)super.peer;
- if (peer != null) {
- peer.setText(label);
- }
- }
-
- }
-
- protected String paramString() {
- String str = ",align=";
- switch (this.alignment) {
- case 0:
- str = str + "left";
- break;
- case 1:
- str = str + "center";
- break;
- case 2:
- str = str + "right";
- }
-
- return super.paramString() + str + ",label=" + this.label;
- }
- }
-