这是我的主要内容:
我试图将JFrame中出现的Ship.png
图像作为我的JButtons的基础。目前,它位于我的所有按钮之上,并且掩盖了所有内容。我似乎无法找到一种方法将图像推到我的JButtons后面。
import javax.swing.JFrame;
import java.io.*;
import javax. imageio.*;
import javax.swing.*;
public class Project2_JoshuaLucas
{
public static void main(String[] args)
{
JFrame main_frame = new JFrame("Select a Cabin or Suite!"); // Sets title for the JFrame
try {
main_frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(newFile("Ship.png")))));
}catch(IOException e)
{
System.out.println("Image doesn't exist.");
}
main_frame.setLocationRelativeTo(null);
main_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Closes JFrame when exiting
Cabin_Choice choice = new Cabin_Choice("", "", "", "", "", "", "", 0.00); // Calls the constructor of my Cabin_Choice class
main_frame.getContentPane().add(choice); // Places choice into the current JFrame pane
main_frame.pack(); // Sizes the frame
main_frame.setVisible(true); // Allows us to see the frame
} // Ends the main method
} // Ends the class
这是我的第二个文件。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Suite_Selector extends JPanel
{
final private JLabel description;
final private JRadioButton cabin1;
description = new JLabel ("Please select the cabin/suite you'll be staying in:");
cabin1 = new JRadioButton("Cabin 11-1");
cabin1.setBackground(Color.gray); //Background color
ButtonGroup group = new ButtonGroup();
group.add(cabin1);
Cabin_Listener the_cabin = new Cabin_Listener();
cabin1.addActionListener(the_cabin);
add(description);
add(cabin1);
setPreferredSize(new Dimension(350, 200));
}