Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class Main {
    private JFrame frame = new JFrame();
    private JDialog dialog = new JDialog();
    private JButton start1 = new JButton("Pick Me");
    private JButton start2 = new JButton("Close");
    private Point pnt = null;
    private Dimension dim = null;

    public Main() {
        start2.addActionListener(e -> dialog.setVisible(false));
        dialog.add(start2, BorderLayout.SOUTH);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setUndecorated(true);
        dialog.setVisible(false);
        start1.addActionListener(e -> {
            dim = frame.getSize();
            pnt = frame.getLocationOnScreen();
            int x = dim.width - 8;
            int y = dim.height - 8;
            dialog.setSize(x, y);
            x = pnt.x + 4;
            y = pnt.y + 4;
            dialog.setLocation(x, y);
            visibleForJDialog();
        });
        frame.add(start1, BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(150, 150);
        frame.setSize(300, 300);
        frame.setVisible(true);
    }

    private void visibleForJDialog() {
        dialog.setVisible(true);
    }

    public static void main(final String args[]) {
        Main uPF = new Main();
    }
}