-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQBPlatform.java
More file actions
68 lines (59 loc) · 1.34 KB
/
QBPlatform.java
File metadata and controls
68 lines (59 loc) · 1.34 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @author Edgar Quillion <edgarquill@gmail.com>
* @version Version 1
* @since 1.6
*/
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
/**
* Platform with bounding box
*/
public class QBPlatform extends QBBox
{
private BufferedImage image;
/**
* Constructor for the platform, originally contains no image
*/
public QBPlatform()
{
super();
image = null;
}
/**
* Load the image from a given path,
* @return true if image loaded successfully, false otherwise
*/
public boolean loadImage(String path)
{
URL url = this.getClass().getResource(path);
this.image = null;
try
{
this.image = ImageIO.read(url);
}
catch (Exception e)
{
return false;
}
super.setWidth(image.getWidth());
super.setHeight(image.getHeight());
return true;
}
/**
* Returns this platform's image
* @return image of this platform
*/
public BufferedImage getImage()
{
return this.image;
}
/**
* Draws image for the platform to the specified canvas
*/
public void draw(Graphics2D g)
{
g.drawImage(this.image, null, super.getX(), super.getY());
}
}