Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

    <p>The code above generates the following result.</p><myResult>PERPIXEL_TRANSPARENT supported:true TRANSLUCENT supported:true PERPIXEL_TRANSLUCENT supported:true</myResult>===SectionShortTitle:Transparent window SectionLongTitle:Transparent window SectionContent:

    <p>The following code shows how to create a transparent window.</p><myPreCode>

    import java.awt.BorderLayout;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;

    public class Main extends JFrame {
        public Main() {
            super();
            JButton closeButton = new JButton("Close");
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.setUndecorated(true);
            this.setOpacity(0.80f);
            this.setSize(200, 200);
            // Center it on the screen
            this.setLocationRelativeTo(null);
            this.add(closeButton, BorderLayout.SOUTH);
            closeButton.addActionListener(e -> System.exit(0));
        }

        public static void main(String[] args) {
            SwingUtilities.invokeLater(() -> {
                Main frame = new Main();
                frame.setVisible(true);
            });
        }
    }</myPreCode>===SectionShortTitle:

    Gradient Window SectionLongTitle:
    Gradient Window SectionContent:

    <p>
The following
    code uses
    JPanel to
    create a
    gradient effect
    from opaque
    at the
    left edge
    to gradually
    turning transparent
    at the
    right edge.</p>