0

Just imported an image, but need a subPanel on the right with the dimensions (200,700) I've tried using the imported image as a panel but it just spans me with errors, any ideas?

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);
Harrison
  • 1
  • 2

1 Answers1

1

You have 3 JFrames in your code. You create a frame in the main method. Then you create a Dodge class which is a JFrame. Finally in the constructor of the Dodge class you create another frame.

I suggest your read the Swing tutorial on How to Use Icons for working examples that will show you how to better structure your program. Then it should be easier to solve your problem.

camickr
  • 321,443
  • 19
  • 166
  • 288