KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > example > SimpleApp


1 /*
2     Launch4j (http://launch4j.sourceforge.net/)
3     Cross-platform Java application wrapper for creating Windows native executables.
4
5     Copyright (C) 2004, 2006 Grzegorz Kowal
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */

21
22 package net.sf.launch4j.example;
23
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Toolkit JavaDoc;
26 import java.awt.event.WindowAdapter JavaDoc;
27 import java.awt.event.WindowEvent JavaDoc;
28
29 import javax.swing.JFrame JavaDoc;
30 import javax.swing.JMenu JavaDoc;
31 import javax.swing.JMenuBar JavaDoc;
32 import javax.swing.JMenuItem JavaDoc;
33 import javax.swing.JOptionPane JavaDoc;
34 import javax.swing.UIManager JavaDoc;
35
36 public class SimpleApp extends JFrame JavaDoc {
37     public SimpleApp(String JavaDoc[] args) {
38         super("Java Application");
39         final int inset = 100;
40         Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
41         setBounds (inset, inset,
42                 screenSize.width - inset * 2, screenSize.height - inset * 2);
43
44         JMenu JavaDoc menu = new JMenu JavaDoc("File");
45         menu.add(new JMenuItem JavaDoc("Open"));
46         menu.add(new JMenuItem JavaDoc("Save"));
47         JMenuBar JavaDoc mb = new JMenuBar JavaDoc();
48         mb.setOpaque(true);
49         mb.add(menu);
50         setJMenuBar(mb);
51
52         this.addWindowListener(new WindowAdapter JavaDoc() {
53             public void windowClosing(WindowEvent JavaDoc e) {
54                 System.exit(0);
55         }});
56         setVisible(true);
57
58         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Java version: ");
59         sb.append(System.getProperty("java.version"));
60         sb.append("\nJava home: ");
61         sb.append(System.getProperty("java.home"));
62         sb.append("\nCurrent dir: ");
63         sb.append(System.getProperty("user.dir"));
64         if (args.length > 0) {
65             sb.append("\nArgs: ");
66             for (int i = 0; i < args.length; i++) {
67                 sb.append(args[i]);
68                 sb.append(' ');
69             }
70         }
71         JOptionPane.showMessageDialog(this,
72                 sb.toString(),
73                 "Info",
74                 JOptionPane.INFORMATION_MESSAGE);
75     }
76
77     public static void setLAF() {
78         JFrame.setDefaultLookAndFeelDecorated(true);
79         Toolkit.getDefaultToolkit().setDynamicLayout(true);
80         System.setProperty("sun.awt.noerasebackground","true");
81         try {
82             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
83         } catch (Exception JavaDoc e) {
84             System.err.println("Failed to set LookAndFeel");
85         }
86     }
87
88     public static void main(String JavaDoc[] args) {
89         setLAF();
90         new SimpleApp(args);
91     }
92 }
93
Popular Tags