Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Container;

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

public class Main {
    public static void main(String[] args) {
        JFrame frame = new JFrame("SpringLayout2");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container contentPane = frame.getContentPane();
        SpringLayout springLayout = new SpringLayout();
        contentPane.setLayout(springLayout);

        JButton b1 = new JButton("Button 1");
        JButton b2 = new JButton("Button Second");

        contentPane.add(b1);
        contentPane.add(b2);

        springLayout.putConstraint(SpringLayout.WEST, b1, 10, SpringLayout.WEST, contentPane);
        springLayout.putConstraint(SpringLayout.NORTH, b1, 20, SpringLayout.NORTH, contentPane);

        springLayout.putConstraint(SpringLayout.WEST, b2, 10, SpringLayout.EAST, b1);

        springLayout.putConstraint(SpringLayout.NORTH, b2, 20, SpringLayout.NORTH, contentPane);

        springLayout.putConstraint(SpringLayout.SOUTH, contentPane, 10, SpringLayout.SOUTH, b1);

        springLayout.putConstraint(SpringLayout.EAST, contentPane, 10, SpringLayout.EAST, b2);

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