seeting background image or color in JFrame in swing
@radha-BTDzli
•
Oct 15, 2024
Oct 15, 2024
2.1K
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.