Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setMaximumSize(new Dimension(350, 250));
        frame.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent evt) {
                Dimension size = frame.getSize();
                Dimension max = frame.getMaximumSize();
                if (size.getWidth() > max.getWidth()) {
                    frame.setSize((int) max.getWidth(), (int) size.getHeight());
                }
                if (size.getHeight() > max.getHeight()) {
                    frame.setSize((int) size.getWidth(), (int) max.getHeight());
                }
            }
        });
        frame.setSize(200, 100);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}