Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] argv) throws Exception {
        JFrame frame = new JFrame();
        GridBagLayout gbl = new GridBagLayout();

        frame.setLayout(gbl);
        JButton component = new JButton("1");
        frame.add(component);
        frame.add(new JButton("2"));

        gbl.layoutContainer(frame);

        GridBagConstraints gbc = new GridBagConstraints();

        gbc.fill = GridBagConstraints.HORIZONTAL;

        gbl.setConstraints(component, gbc);
        frame.add(component);

        frame.pack();
        frame.setVisible(true);
    }
}