Java & J2EE Page 4 - Java's Basic User Interface Components |
Labels are created via the Label class. Labels are often used to identify the purpose of other components on a given interface; they cannot be edited directly by the user. Using a label is much easier than using a drawString( ) method because labels are drawn automatically and don’t have to handled explicitly in the paint( ) method. Labels can be laid out according to the layout manager, instead of using [x, y] coordinates, as in drawString( ). To create a Label, use one of the following constructors:
Example 3 The following is a simple applet that creates a few labels in Helvetica bold. /*We can use label’s getText( ) method to indicate the current label’s text and setText( ) method to change the label’s text. We have also made use of setFont( ) method in the above example to change the label’s font and GridbagLayout to lay the components in the applet.
blog comments powered by Disqus |