/* * File: LabelTest.java * * Create some text labels * * Copyright: Northeast Parallel Architectures Center * */ import java.awt.*; import javax.swing.*; import java.net.*; public class LabelTest extends JApplet { private JLabel label0, label1, label2; private Font f = new Font ("Serif", Font.BOLD, 24 ); private ImageIcon icon1, icon2, icon3; public void init() { try { icon1=new ImageIcon(new URL("http://www.npac.syr.edu/projects/webtech/java/examples1.2/labeltest/left.gif")); icon2=new ImageIcon(new URL("http://www.npac.syr.edu/projects/webtech/java/examples1.2/labeltest/center.gif")); icon3=new ImageIcon(new URL("http://www.npac.syr.edu/projects/webtech/java/examples1.2/labeltest/right.gif")); } catch (Exception e){} // create each label, set its characteristics and "add" it to the applet getContentPane().setLayout(new GridLayout()); getContentPane().setBackground( Color.white ); // By default, a label is left-aligned: label0 = new JLabel(icon1, JLabel.LEFT); label0.setText( "aligned left " ); label0.setFont (f); label1 = new JLabel( "aligned center", icon2, JLabel.CENTER ); label1.setForeground( Color.blue ); label1.setFont( new Font( "Monospaced", Font.BOLD, 24 ) ); label2 = new JLabel( " aligned right", icon3, JLabel.RIGHT ); label2.setFont (f); getContentPane().add( label0 ); getContentPane().add( label1 ); getContentPane().add( label2 ); } }