Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame frame = new JFrame() {
            @Override
            public synchronized void setExtendedState(int state) {
                if (isUndecorated() && (state & MAXIMIZED_BOTH) == MAXIMIZED_BOTH) {
                    super.setMaximizedBounds(new Rectangle(300, 300));
                }
                super.setExtendedState(state);
            }
        };
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        frame.setUndecorated(true);
        frame.getContentPane().add(new JButton(new AbstractAction("Toggle maximize") {
            @Override
            public void actionPerformed(ActionEvent e) {
                int state = frame.getExtendedState();
                if ((state & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
                    frame.setExtendedState(JFrame.NORMAL);
                } else {
                    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                }
            }
        }), BorderLayout.PAGE_END);
        frame.setVisible(true);
    }
}