0

How would I import an image and make it the background of my program?

I have tried the drawing method but it failed.

package Control;

import java.awt.Color;
import javax.swing.JFrame;

public class Control extends JFrame {

    private static final long serialVersionUID = 1L;

    public Control() {
        setSize(500, 500);
        setTitle("Asteroid: Save Humanity");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new Control();
    }

}
Celeo
  • 5,583
  • 8
  • 39
  • 41

2 Answers2

0

To make a JPanel with a backround, check out this link. It's fairly simple, just create a new instance of this class, it will behave like a JPanel. You can always modify it so that the you set the content pane to this image. If nothing else, use it for reference.

Basicly, it creates a new instance of Image from a String or ImageIcon, and uses drawImage() to render it.

CaffeineToCode
  • 830
  • 3
  • 13
  • 25
0

Make jframe operations in main method and use jpanel for making background. Use paintComponent for drawing image or use image icon.

amar
  • 11
  • 5