Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Component;
import java.awt.Container;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JPanel;
import javax.swing.JRootPane;

public class Main {
    /**
     * @param okText
     * @param listener
     * @return newly created JPanel with ok and cancel buttons
     */
    public static JPanel createOkPanel(String okText, ActionListener listener) {
        return createOkPanel(okText, listener, null);
    }

    /**
     * @param okText
     * @param listener
     * @param root 
     * @return newly created JPanel with ok and cancel buttons
     */
    public static JPanel createOkPanel(String okText, ActionListener listener, JRootPane root) {
        JPanel panel = new JPanel();
        JButton ok = new JButton(okText);
        panel.add(ok);
        ok.addActionListener(listener);
        ok.setActionCommand(okText);
        if (root != null)
            root.setDefaultButton(ok);
        return panel;
    }

    /**
     * @param gx
     * @param gy
     * @param gw
     * @param gh
     * @param wx
     * @param wy
     * @param what
     * @param where
     * @param gbc
     * @param gridbag
     */
    public static void add(int gx, int gy, int gw, int gh, int wx, int wy, Component what, Container where,
            GridBagConstraints gbc, GridBagLayout gridbag) {
        gbc.gridx = gx;
        gbc.gridy = gy;
        gbc.gridwidth = gw;
        gbc.gridheight = gh;
        gbc.weightx = wx;
        gbc.weighty = wy;
        gridbag.setConstraints(what, gbc);
        where.add(what);
    }
}