-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawable.java
More file actions
58 lines (52 loc) · 1.6 KB
/
Drawable.java
File metadata and controls
58 lines (52 loc) · 1.6 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
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
public abstract class Drawable {
private int x = 0, y = 0, width = 10, height = 10;
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public abstract void draw(Graphics2D g2);
public abstract void update();
protected Clip getSound(String filename) {
Clip clip = null;
try {
InputStream in = getClass().getResourceAsStream( filename );
InputStream buf = new BufferedInputStream( in );
AudioInputStream stream = AudioSystem.getAudioInputStream( buf );
clip = AudioSystem.getClip();
clip.open( stream );
} catch (UnsupportedAudioFileException |
IOException | LineUnavailableException e) {
e.printStackTrace();
}
return clip;
}
protected Image getImage(String filename) {
URL url = getClass().getResource( filename );
ImageIcon icon = new ImageIcon( url );
return icon.getImage();
}
}