create a swing application
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
|
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Test3 extends JApplet {
public void init() {
Container contentPane = getContentPane();
Icon icon = new ImageIcon(ClassLoader.getSystemResource("swing.gif"));
JLabel label = new JLabel(icon);
// java.net.URL codebase = getClass().getResource("../swing.gif");
// JLabel label = new JLabel(new ImageIcon(codebase));
contentPane.setLayout(new FlowLayout());
contentPane.add(label);
}
public static void main(String args[]) {
final JFrame f = new JFrame();
JApplet applet = new Test3();
applet.init();
f.setContentPane(applet.getContentPane());
f.setBounds(100, 100, 308, 199);
f.setTitle("An Application");
f.setVisible(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
} |
Tags: java, swing
This entry was posted
on Friday, September 11th, 2009 at 3:34 pm and is filed under swing.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.