Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

public class Main {
    /**
     * Returns a preferrable window size for the application
     * @return
     */
    public static Dimension getPreferrableWindowSize() {
        int margin = 100;
        Dimension size = getEffectiveScreenSize();
        float aspect = size.width / (size.height * 1.0f);
        int newHeight = size.height - margin;
        int newWidth = (int) (newHeight * aspect);
        return new Dimension(newWidth, newHeight);
    }

    /**
     * Returns current screen size of the display. In case of multi-display system it returns the
     * screen size for default one.
     * @return
     */
    public static Dimension getEffectiveScreenSize() {
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int width = gd.getDisplayMode().getWidth();
        int height = gd.getDisplayMode().getHeight();
        return new Dimension(width, height);
    }
}