This is my java code.What I'm trying to do is,keep the image as background and keep the buttons on top.But the image overwrites my base form.I'm only a beginner.so please help me.
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.*; class petbegin extends JPanel { JLabel title; JLabel caption; JButton chief; JButton vet; JButton recept; public petbegin() { setLayout(null); title=new JLabel("A VET'S PET"); caption=new JLabel("Nothing but the best for your pet!"); chief=new JButton("Chief Doctor's Login"); vet=new JButton("Assistant Vets' Login"); recept=new JButton("Receptionist's Login"); Font f1=new Font("Castellar",Font.BOLD,28); Font f=new Font("Castellar",Font.BOLD,32); Font f2=new Font("Calibri",Font.BOLD,20); title.setFont(f); caption.setFont(f1); chief.setFont(f2); vet.setFont(f2); recept.setFont(f2); add(title); add(caption); add(chief); add(vet); add(recept); title.setBounds(335,100,500,40); caption.setBounds(155,180,900,30); chief.setBounds(285,290,300,30); vet.setBounds(260,370,350,30); recept.setBounds(285,450,300,30); } } class imageframe extends JPanel { Image img=new ImageIcon("welcome.jpg").getImage(); public void paintComponent(Graphics g) { g.drawImage(img,0,0,this); } } class space extends JPanel { } class welcome extends JFrame { public static void main(String args[]) { JPanel spc=new space(); spc.setLayout(new OverlayLayout(spc)); spc.add(new imageframe(),BorderLayout.CENTER); spc.add(new petbegin(),BorderLayout.CENTER); welcome t=new welcome(); t.setContentPane(spc); t.setVisible(true); t.setSize(1000,650); } }