I am creating a Flight Reservation system for a project, having trouble with the GUI of the app. I am using a CardLayout to manage the multiple cards for this program.
In the login card I am trying to add a background image, but the input fields are shown below the image.
The code for the program is
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.imageio.*;
import java.net.*;
public class CardPanel {
public static void main(String[] args) {
try {
CardLayout cardLayout = null;
JFrame frame = new JFrame("Welcome");
JPanel contentPane = new JPanel(cardLayout);
URL url = new URL("https://i.stack.imgur.com/P59NF.png");
BufferedImage img = ImageIO.read(url);
ImageIcon imageIcon = new ImageIcon(img);
JLabel logo = new JLabel(imageIcon);
JPanel buttonsPanel = new JPanel();
JButton login = new JButton("Login");
buttonsPanel.add(login);
contentPane.setLayout(new BorderLayout(10, 15));
contentPane.add(logo, BorderLayout.NORTH);
contentPane.add(buttonsPanel, BorderLayout.SOUTH);
frame.add(contentPane, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
A screenshot of the app is also attached (https://i.stack.imgur.com/KkEcz.png).
I would like the button to be above the background image.