Hello i am developing a custom clock application.
My GUI works find my functionality is fine however i have one problem for 3 days now. I can't get my GUI to display an image in the background without hiding my components.
here is my code of the GUI class
public void makeFrame() {
contentPane.setLayout(new BorderLayout());
contentPane.add(panel1, BorderLayout.NORTH);
contentPane.add(panel2, BorderLayout.CENTER);
contentPane.add(panel3, BorderLayout.SOUTH);
contentPane.add(panel4, BorderLayout.WEST);
contentPane.add(panel5, BorderLayout.EAST);
panel1.add(label1);
panel2.setLayout(new GridLayout(3,4));
panel2.add(time);
panel2.add(label2);
panel2.add(stopwatch);
panel3.setLayout(new FlowLayout());
panel4.setLayout(new FlowLayout());
panel5.add(alarm);
panel5.add(change);
panel5.setLayout(new FlowLayout());
label1.setFont(new Font("Arial", Font.PLAIN, 90));
label1.setForeground(Color.BLUE);
label2.setFont(new Font("Arial", Font.PLAIN, 70));
label2.setForeground(Color.RED);
time.setEditable(true);
time.setText("Sample Time: n/ 13:45:23 ");
time.setFont(new Font("Arial", Font.PLAIN, 60));
stopwatch.setFont(new Font("Arial", Font.PLAIN, 45));
stopwatch.setSize(20,20);
stopwatch.setText("00 : 00 : 00");
stopwatch.setEditable(false);
stopwatch.add(rounds);
frame = new JFrame("Clock");
frame.setLayout(null);
frame.setSize(600,900);
paint();
frame.setContentPane(contentPane);
makeMenu();
comboBox();
stopWatch();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.validate();
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
and the paint() method
public void paint() {
BufferedImage img = null;
try {
//load the image
img = ImageIO.read(new File("C:/Users/User/workspace/Alarm Clock/src/Clock/clock.jpg"));
ImageIcon image = new ImageIcon(img);
JLabel label = new JLabel(image);
frame.setContentPane(label);
} catch (IOException e) {
}
}