Hello JFrame

A simple java window program


Introduction

A simple java window program to show usage of Windows type of application.


1. Edit a java source file: "X:\demos\src\hello\HelloJFrame.java"

package hello;

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;

public class HelloJFrame extends JFrame {

    private static final long serialVersionUID = 1L;

    private JPanel jContentPane = null;

    /**
     * @param args
     */
    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                HelloJFrame thisClass = new HelloJFrame();
                thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                thisClass.setVisible(true);
            }
        });
    }

    /**
     * This is the default constructor
     */
    public HelloJFrame() {
        super();
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize(300, 200);
        this.setContentPane(getJContentPane());
        this.setTitle("JFrame");
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
        }
        return jContentPane;
    }

}

2. Enter "X:\demos" directory and compile it to a class file:

X:\>cd demos
X:\demos>javac src/hello/HelloJFrame.java

3. Make a jar file:

X:\demos>jar -cvf hellojframe.jar -C src .

4. Use Jar2Exe to generate exe file for Windows and Linux separately:

X:\demos>j2ewiz hellojframe.jar /m hello.HelloJFrame /type windows
X:\demos>j2ewiz hellojframe.jar /m hello.HelloJFrame /type windows /platform linux

5. Download the program for reference.


See Also