刚刚导入了一个图像,但在右侧需要一个尺寸为 (200,700) 的子面板 我尝试将导入的图像用作面板,但它只是让我出现错误,有什么想法吗?
package dodge;
import java.awt.*;
import javax.swing.*;
public class Dodge extends JFrame {
private ImageIcon image;
private JLabel label;
Dodge(){
JFrame frame = new JFrame();
frame.setResizable(false);
frame.pack();
setLayout(new FlowLayout());
JPanel image = new JPanel();
image = new ImageIcon(getClass().getResource("Road.jpg"));
label = new JLabel (image);
add(label);
}
public static void main(String[] args) {
//
JFrame frame = new JFrame();
frame.setResizable(false);
frame.pack();
Dodge gui = new Dodge();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
gui.pack();
gui.setTitle("Dodge The Cars");
JPanel subPanel1= new JPanel();
subPanel1.setBackground(Color.DARK_GRAY);
subPanel1.setPreferredSize(new Dimension (250,700));
JLabel label = new JLabel ("Menu");
subPanel1.add(label);