// This code example is created for educational purpose
// by Thorsten Thormaehlen (contact: www.thormae.de).
// It is distributed without any warranty.

import javax.swing.*;
import java.awt.*;

class MyGui extends JFrame{
  public void createGUI() {
    setTitle("HelloGUI");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(320, 240);

    String[] labels = {"Firstname: ", "Lastname: ", "Student ID: ", "Enrolled since: "};

    Container contentPane = getContentPane();
    contentPane.setLayout(new SpringLayout());
    for (int i = 0; i < labels.length; i++) {
        JLabel label = new JLabel(labels[i], JLabel.TRAILING);
        contentPane.add(label);
        JTextField textField = new JTextField(10);
        label.setLabelFor(textField);
        contentPane.add(textField);
    }

    SpringUtilities.makeCompactGrid(contentPane, labels.length, 2, 5, 5, 5, 5);
    
    pack(); // dense packing
    setVisible(true);
  }
}

public class MySpringLayout {
  public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        MyGui myGUI = new MyGui();
        myGUI.createGUI();
      }
    });
  }
}
