Hi Expert,
I am a newbies in java and i am trying to creat an image as a background on a GUI i created, but i am not getting any image dispalying as bacground. I need to connect this GUI on DB2:
Here is the code i have maybe someone can see where i am going wrong and then modify the code for me to get the image:
Code:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
 
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
public class NewClass3 {
 
  public static void main(String[] args) {
    ImagePanel panel = new ImagePanel(new ImageIcon("C:\\myimage.jpg").getImage());
 
    JFrame frame = new JFrame();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
}
 
class ImagePanel extends JPanel {
 
  private Image img;
 
  public ImagePanel(String img) {
    this(new ImageIcon(img).getImage());
  }
 
  public ImagePanel(Image img) {
    this.img = img;
    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
    setSize(size);
    setLayout(null);
  }
 
  public void paintComponent(Graphics g) {
    g.drawImage(img, 0, 0, null);
  }
Can some help me please?
Thanks