Basic HTML version of Foils prepared Sept 21 1998

Foil 31 Basic AWT Component: Label

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

Labels for Foil 31
This is an area where text can be displayed in the window.
Create an instance of the Label class and add it to the window:
  • Label label1 = new Label ( "aligned left");
  • add (label1);
Another constructor allows a second argument which is an alignment: Label.LEFT, Label.CENTER, or Label.RIGHT
  • Label label2 = new Label ("aligned right", Label.RIGHT);
Method setText allows you to change the String in the Label, and getText() returns the current String
  • label2.setText("another message");
aligned left aligned right



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998