Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JSlider;
import javax.swing.JTextField;

public class Main extends javax.swing.JFrame {
    JSlider slider = new JSlider();
    JButton btnNewButton = new JButton("Do");
    JDialog d = new JDialog();
    JTextField text = new JTextField();

    public Main() {
        btnNewButton.addActionListener(e -> d.setVisible(true));
        getContentPane().add(btnNewButton, BorderLayout.CENTER);

        slider.addChangeListener(e -> text.setText(Integer.toString(slider.getValue())));

        getContentPane().add(slider, BorderLayout.NORTH);
        d.getContentPane().add(text);
        d.pack();

        pack();
        setVisible(true);
    }

    public static void main(String args[]) {
        new Main().setVisible(true);
    }
}