package ru.cdmlex.jtest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DesktopJGameBuilder {
    public static JGame build(Dimension screenSize, int wx) {
        final CanvasJGame jgame = new CanvasJGame(screenSize, wx);
        JFrame frame = new JFrame();
        frame.setFocusable(false);
        frame.setResizable(false);
        frame.setLayout(new BorderLayout());
        frame.add(jgame);
        frame.pack();
        frame.setVisible(true);
        jgame.createBufferStrategy(2);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent event) {
                jgame.pause();
            }
        });
        frame.requestFocus();
        jgame.requestFocus();
        return jgame;
    }
}
