48 lines
1.8 KiB
Java
48 lines
1.8 KiB
Java
/* GameFrame class establishes the frame (window) for the game
|
|
It is a child of JFrame because JFrame manages frames
|
|
Runs the constructor in GamePanel class
|
|
|
|
*/
|
|
import java.awt.*;
|
|
import java.io.IOException;
|
|
import java.util.Set;
|
|
import javax.sound.sampled.LineUnavailableException;
|
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
|
import javax.swing.*;
|
|
|
|
public class GameFrame extends JFrame{
|
|
|
|
MenuPanel menu;
|
|
GamePanel game;
|
|
SettingPanel settings;
|
|
CameraPanel main;
|
|
|
|
public GameFrame(){
|
|
try {
|
|
main = new CameraPanel();
|
|
main.setLayout(new CardLayout());
|
|
menu = new MenuPanel(main);
|
|
game = new GamePanel(main); //run GamePanel constructor
|
|
settings = new SettingPanel(main);
|
|
main.add(menu, "menu");
|
|
main.add(settings, "settings");
|
|
main.add(game, "game");
|
|
} catch (IOException | SpriteException | UnsupportedAudioFileException | LineUnavailableException e) {
|
|
// TODO: handle IO errors gracefully
|
|
// exceptions are raised when tiles are not found or are of incorrect dimensions
|
|
}
|
|
this.add(main);
|
|
this.setTitle("GUI is cool!"); //set title for frame
|
|
// set game icon and ignore exception (failing to set icon doesn't otherwise break program)
|
|
try {
|
|
this.setIconImage(GamePanel.getImage("img/misc/favicon.png"));
|
|
} catch (IOException ignored) {}
|
|
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
|
|
}
|
|
|
|
} |