seeting background image or color in JFrame in swing

radha gogia

radha gogia

@radha-BTDzli Oct 15, 2024
public class JavaApplication12 extends JFrame {
    public void go()
      {
           JFrame frame=new JFrame();
        JButton wel=new JButton("WELCOME TO NOTE-MAKING STORE");
         Container c = JFrame.getContentPane();
         c.setBackground(Color.red);
    
      
  
       try{
        frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("E:\\ad5.jpg")))));
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
      
      
         frame.getContentPane().add(wel);
         frame.setSize(1500,1500);
         frame.setVisible(true);
      
       //  frame.setContentPane(new JLabel(new ImageIcon("D:\\ad4.png")));
        
   wel.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e)
        {
            new video();

        }
    });
      }
    public static void main(String[] args) {
       JavaApplication12 obj=new JavaApplication12();
       obj.go();
        }
  

    }

I am getting 2 errors,one is the background image is just attached to the centre so I am unable to see the button which was placed already in the centre

then secondly my background color is not set for the frame.

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform