Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

public class Main {
    public static void main(String[] args) {
        JTextField[] txtAllAverages;
        int testCount = 2;

        txtAllAverages = new JTextField[testCount];

        JPanel inputControls = new JPanel(new BorderLayout(5, 5));

        JPanel inputControlsLabels = new JPanel(new GridLayout(0, 1, 3, 3));
        JPanel inputControlsFields = new JPanel(new GridLayout(0, 1, 3, 3));
        inputControls.add(inputControlsLabels, BorderLayout.WEST);
        inputControls.add(inputControlsFields, BorderLayout.CENTER);
        for (int i = 0; i < testCount; i++) {
            inputControlsLabels.add(new JLabel("Test score: "));
            JTextField field = new JTextField(10);
            inputControlsFields.add(field);
            txtAllAverages[i] = field;
        }

        JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));

        controls.add(new JButton("Reset"));
        controls.add(new JButton("Submit"));

        JPanel gui = new JPanel(new BorderLayout(10, 10));
        gui.setBorder(new TitledBorder("Averages"));
        gui.add(inputControls, BorderLayout.CENTER);
        gui.add(controls, BorderLayout.SOUTH);

        JFrame f = new JFrame();
        f.setContentPane(gui);

        f.pack();
        f.setLocationByPlatform(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}