-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJLabel_Test.java
More file actions
54 lines (42 loc) · 1.56 KB
/
JLabel_Test.java
File metadata and controls
54 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jLabeltest;
//LabelTest.java
//Demonstrating the JLabel class.
//Java core packages
import java.awt.*;
import java.awt.event.*;
//Java extension packages
import javax.swing.*;
public class JLabel_Test extends JFrame {
JLabel label1, label2, label3;
//set up GUI inside the constructor
public JLabel_Test() {
super( "JLabel" );
//get content pane and set its layout
Container container = getContentPane();
container.setLayout( new FlowLayout() );
//JLabel constructor with a string argument
label1 = new JLabel( "Label with text" );
label1.setToolTipText( "This is label1" );
container.add( label1 );
//JLabel constructor with string, Icon and alignment arguments
Icon bug = new ImageIcon( "bug1.gif" );
label2 = new JLabel( "Label with text and icon", bug, SwingConstants.LEFT );
label2.setToolTipText( "This is label2" );
container.add( label2 );
//JLabel constructor no arguments
label3 = new JLabel();
label3.setText( "Label with icon and text at bottom" );
label3.setIcon( bug );
label3.setHorizontalTextPosition( SwingConstants.CENTER );
label3.setVerticalTextPosition( SwingConstants.BOTTOM );
label3.setToolTipText( "This is label3" );
container.add( label3 );
setSize( 475, 170 );
setVisible( true );
}
//execute application
public static void main( String args[] ) {
JLabel_Test application = new JLabel_Test();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class LabelTest