final/src/GameFrame.java

25 lines
858 B
Java
Raw Normal View History

2022-05-30 19:46:53 +01:00
/* GameFrame class establishes the frame (window) for the game
2022-05-30 19:36:18 +01:00
It is a child of JFrame because JFrame manages frames
2022-05-30 19:46:53 +01:00
Runs the constructor in GamePanel class
*/
2022-05-30 19:36:18 +01:00
import java.awt.*;
import javax.swing.*;
public class GameFrame extends JFrame{
2022-05-30 19:46:53 +01:00
GamePanel panel;
2022-05-30 19:36:18 +01:00
2022-05-30 19:46:53 +01:00
public GameFrame(){
panel = new GamePanel(); //run GamePanel constructor
this.add(panel);
this.setTitle("GUI is cool!"); //set title for frame
this.setResizable(false); //frame can't change size
this.setBackground(Color.white);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //X button will stop program execution
this.pack();//makes components fit in window - don't need to set JFrame size, as it will adjust accordingly
this.setVisible(true); //makes window visible to user
this.setLocationRelativeTo(null);//set window in middle of screen
}
2022-05-30 19:36:18 +01:00
}