Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame {
    public Main() {
        Box box = new Box(BoxLayout.Y_AXIS);
        add(box);

        JLabel label = new JLabel("I'm centered");
        label.setAlignmentX(JComponent.CENTER_ALIGNMENT);

        box.add(Box.createVerticalGlue());
        box.add(label);
        box.add(Box.createVerticalGlue());
    }

    public static void main(String[] args) {
        Main frame = new Main();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}