An image is being displayed on JLabel and the text is displayed right to it. I want the image to be the background of JLabel and the text should be displayed over it.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TestGUI extends JFrame implements MouseMotionListener {
JLabel l1;
TestGUI() {
l1 = new JLabel();
getContentPane().setBackground(Color.GREEN);
setLayout(null);
l1.setBounds(50, 80, 600, 60);
l1.setIcon(new ImageIcon("E:\\subjects\\JAVA\\Internet Images\\blue.jpg"));
l1.setFont(new Font("Jokerman", 3, 20));
addMouseMotionListener(this);
add(l1);
show();
setSize(600, 500);
setDefaultCloseOperation(3);
}
public void mouseMoved(MouseEvent me) {
l1.setText("x=" + me.getX() + " y=" + me.getY());
System.out.println("mouseMoved");
}
public void mouseDragged(MouseEvent me) {
System.out.println("mouseDragged");
}
public static void main(String x[]) {
new TestGUI();
}
}