Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Main extends JFrame {

    Main() {
        getRootPane().setGlassPane(new JComponent() {
            public void paintComponent(Graphics g) {
                g.setColor(new Color(0, 0, 0, 100));
                g.fillRect(0, 0, getWidth(), getHeight());
                super.paintComponent(g);
            }
        });
        JButton popDialog = new JButton("Block Frame");
        popDialog.addActionListener(e -> {
            getRootPane().getGlassPane().setVisible(true);
            JOptionPane.showMessageDialog(Main.this, "Shady!");
            getRootPane().getGlassPane().setVisible(false);
        });
        setContentPane(popDialog);
        pack();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(350, 180);
    }

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