All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.espressoengine.Window Maven / Gradle / Ivy

The newest version!
package io.github.espressoengine;

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

/**
 * Window created with java.awt and javax.swing and featuring a Canvas2D instance.
 *
 * @author pastthepixels
 * @version $Id: $Id
 */
public class Window extends JFrame {

  public Canvas2D canvas = new Canvas2D();

  // CONSTANTS
  final private Vector2 SIZE = new Vector2(600, 800);
  private String TITLE = "JyGame Window";
  public boolean stopOnClose = true;

  // INITIALISING THE WINDOW
  /**
   * 

Constructor for Window.

*/ public Window() { init(); } /** *

Constructor for Window taking a Vector2 as a parameter for the windows's size.

* * @param size a {@link io.github.espressoengine.Vector2} object */ public Window(Vector2 size) { this.SIZE.set(size); init(); } /** *

Constructor for Window with a title.

* * @param title a {@link java.lang.String} object */ public Window(String title) { this.TITLE = title; init(); } /** *

Constructor for Window with both a size and title specified.

* * @param size a {@link io.github.espressoengine.Vector2} object * @param title a {@link java.lang.String} object */ public Window(Vector2 size, String title) { this.SIZE.set(size); this.TITLE = title; init(); } /** *

Creates a new window with javax.swing and java.awt.

*/ public void init() { // sets some properties of the frame setTitle(TITLE); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);// JFrame.EXIT__ON_CLOSE addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { close(); } }); setResizable(false); // creates a pane where we will hold everything, and make it look cool canvas.setPreferredSize(new Dimension((int)SIZE.x, (int)SIZE.y)); add(canvas); pack(); } /** * Displays the window on the screen. */ public void open() { setVisible(true); } /** * Closes the window. If Window.stopOnClose is set to true, it will also stop the entire program. */ public void close() { dispose(); if (this.stopOnClose == true) System.exit(0); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy