create Frame For Test - Java Swing

Java examples for Swing:JFrame

Description

create Frame For Test

Demo Code


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

public class Main{
    public static JFrame createFrameForTest() {
        // Loading LAF
        System.out.println("Loading LAF....");
        try {// w  w  w .  j  av  a2  s .c  o  m
            for (LookAndFeelInfo info : UIManager
                    .getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception e) {
            // If Nimbus is not available, you can set the GUI to another look
            // and feel.
            System.err.println("LAF Nimbus not available, sorry guy...");
        }
        // Create frame
        final JFrame frame = new JFrame();
        frame.setSize(new Dimension(800, 500));
        frame.setTitle("Curling Tools - Test");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                System.out.println("==> FrameTest.terminate()");
                // Closing persistence connections
                PersistenceUtils.finalizePersistence();
                // Quit program
                System.exit(0);
            }
        });
        // Center on screen
        frame.setLocationRelativeTo(null);
        // Layout
        frame.getContentPane().setLayout(new BorderLayout());

        return frame;
    }
}

Related Tutorials