Hai Everyone,
I am J.Shobana i want to add an image to a JLabel. The label is addedm to a JPanel and the panel to JFrame.
I am not able to add image to the panel. The Source code which i am using for it is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyMainClass extends JPanel
{
static JFrame frame;
JPanel panel;
MyMainClass()
{
frame = new JFrame("Image");
panel = new JPanel();
frame.getContentPane().add(panel);
panel.setLayout(null);
JLabel l = new JLabel("Hello");
l.setBounds(600,100,500,500);
JButton b = new JButton("Image");
b.setBounds(100,200,100,100);
Icon logo = new ImageIcon("logo.bmp");
// Place the Icon in the label
l.setIcon(logo);
JLabel l1 = new JLabel("Hai");
l1.setBounds(300,100,100,100);
panel.add(b);
panel.add(l);
panel.add(l1);
frame.add(panel);
}
public static void main(
String args[])
{
MyMainClass m = new MyMainClass();
frame.setVisible(true);
frame.setSize(400,200);
}
}
Here the button and JLabel l is added but the JLabel l1 with the image alone is not been added to the panel.
I tried in all way. Please if anyone caql give me a solution its very urgent.
Thanks in Advance,
J.Shobana.