-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackground.java
More file actions
34 lines (31 loc) · 916 Bytes
/
Background.java
File metadata and controls
34 lines (31 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.io.InputStream;
import javax.swing.JLabel;
import java.awt.Toolkit;
import java.io.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
// Class that creates and places the background image.
public class Background{
BufferedImage img = null;
// Method to return background as JLabel.
public static JLabel getBackground(){
BufferedImage image = null;
try
{
InputStream is = Roadrunner.class.getResourceAsStream("/road.png");
image = ImageIO.read(is);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
ImageIcon imageIcon = new ImageIcon(image);
JLabel jLabel = new JLabel();
jLabel.setIcon(imageIcon);
jLabel.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
return jLabel;
}
}