Thursday, September 9, 2010

Assignment #6 Label Frame & Label Test



/*
Assignment 6 Gabriel Cuevas
*/

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class LabelFrame extends JFrame
{
private JLabel label1; //Just for text
private JLabel label2; //Constructed with text and icon
private JLabel label3; // with added text and icon

public LabelFrame()
{
super( "Testing JLabel" );
setLayout (new FlowLayout() );

//JLabel constructor with string argument
label1 = new JLabel( "Label with text" );
label1.setToolTipText( "This is label1" );
add( label1);

//JLabel constructor with string, Icon and alignment arguments
Icon bug = new ImageIcon( getClass().getResource( "bug1.jpg" ) );
label2 = new JLabel( "Label with text and icon", bug,
SwingConstants.LEFT);
label2.setToolTipText( "This is label2" );
add( label2 );

//JLabel constructor with 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" );
add( label3 );
}
}

SECOND PART

/*
Assignment 6 Main Function Gabriel Cuevas
*/

import javax.swing.JFrame;

public class LabelTest
{
public static void main( String args[] )
{
LabelFrame labelFrame = new LabelFrame(); //creates LabelFrame
labelFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
labelFrame.setSize(275, 180 );
labelFrame.setVisible( true );
}
}

No comments:

Post a Comment