1 |
import javax.swing.ImageIcon; |
2 |
import javax.swing.JFrame; |
3 |
import javax.swing.JLabel; |
4 |
import javax.swing.JPanel; |
5 |
|
6 |
/** |
7 |
This program displays a frame with an image and a text label. |
8 |
*/ |
9 |
public class FrameTest |
10 |
{ |
11 |
public static void main(String[] args) |
12 |
{ |
13 |
JFrame frame = new JFrame(); |
14 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
15 |
|
16 |
JLabel iconLabel = new JLabel(new ImageIcon("world.gif")); |
17 |
JLabel textLabel = new JLabel("Hello, World!"); |
18 |
|
19 |
JPanel panel = new JPanel(); |
20 |
panel.add(iconLabel); |
21 |
panel.add(textLabel); |
22 |
frame.setContentPane(panel); |
23 |
|
24 |
frame.pack(); |
25 |
frame.show(); |
26 |
} |
27 |
} |