-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceTest.java
More file actions
45 lines (40 loc) · 1.23 KB
/
ResourceTest.java
File metadata and controls
45 lines (40 loc) · 1.23 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
package resource;
import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
/**
* @author Cay Horstmann
* @version 1.41 2015-06-12
*/
public class ResourceTest {
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
JFrame frame = new ResourceTestFrame();
frame.setTitle("ResourceTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
/**
* A frame that loads image and text resources.
*/
class ResourceTestFrame extends JFrame {
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 300;
public ResourceTestFrame() {
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
URL aboutURL = getClass().getResource("about.gif");
Image img = new ImageIcon(aboutURL).getImage();
setIconImage(img);
JTextArea textArea = new JTextArea();
InputStream stream = getClass().getResourceAsStream("about.txt");
try (Scanner in = new Scanner(stream, "UTF-8")) {
while (in.hasNext())
textArea.append(in.nextLine() + "\n");
}
add(textArea);
}
}