import javax.swing.Icon;
import javax.swing.ImageIcon;

public class LabelFrame extends JFrame {
	private JLabel label1;
	private JLabel label2;
	private JLabel label3;

	public LabelFrame() {  // zero-argument constructor
		super("Testing JLabel");
		setLayout(new FlowLayout()); // setLayout is inherited from class Container
		// argument of the method must be an object of a class that implements the
		// LayoutManager interface (e.g. FlowLayout) -- this is an anonymous object
		// since the object created by the constructor is not assigned to a variable
		label1 = new JLabel("Label with text");
		label1.setToolTipText("This is label1");
		add(label1);

		Icon bug = new ImageIcon(getClass().getResource("bug1.gif"));
		label2 = new JLabel("Label with text and icon",bug,SwingConstants.LEFT);
		label2.setToolTipText("This is label2");
		add(label2);
		// getClass method (inherited from class Object) returns a reference to the Class
		// object (java.lang.Class) that represents the LabelFrame class declaration.
		// This object is then used to invoke the Class method getResource which returns the
		// location of the image as a URL -- the image file can be created in Paint
		// the SwingConstants are actually integers but using names for the integers avoids
		// having to remember that 0 is for ..., 1 is for ..., etc.

		label3 = new JLabel();
		label3.setText("Label with icon and text as button");
		label3.setIcon(bug);
		label3.setHorizontalTextPosition(SwingConstants.CENTER);
		label3.setVerticalTextPosition(SwingConstants.BOTTOM);
		label3.setToolTipText("This is label3");
		add(label3);

} // end constructor
} // end class