Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

public class Main extends JFrame {
    JProgressBar bar = new JProgressBar();
    JButton step = new JButton("Step");

    public Main() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        step.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int value = bar.getValue() + 7;
                if (value > bar.getMaximum()) {
                    value = bar.getMaximum();
                }
                bar.setValue(value);
            }
        });

        getContentPane().add(bar, BorderLayout.NORTH);
        getContentPane().add(step, BorderLayout.EAST);
        pack();
        setVisible(true);
    }

    public static void main(String arg[]) {
        new Main();
    }
}