Hello,
I am trying to work through an example from a Deitel book. I keep getting a "source not found" error on line 27 of the LabelFrame class. I have put the "bug1.png" in every single directory associated with this project. I am stumped...
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;
private JLabel label2;
private JLabel label3;
// LabelFrame constructor adds JLabels to JFrame (This is the constructor)
public LabelFrame()
{
super( "Testing JLabel" );
setLayout( new FlowLayout()); // set frame layout
// JLabel constructor with a 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.png"));
label2 = new JLabel( "Label with text and icon", bug,
SwingConstants.LEFT);
label2.setToolTipText("This is label2");
add (label2);
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); // add label3 to JFrame
} // end LabelFrame constructor
} // end Class LabelFrame
import javax.swing.JFrame;
//
// Testing LabelFrame
public class LabelTest
{
public static void main(String[] args)
{
LabelFrame labelFrame = new LabelFrame();
labelFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
labelFrame.setSize( 260, 180);
labelFrame.setVisible( true);
} // end main
} // end Class LabelTest