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.*;
|
2022-06-02 18:22:17 +01:00
|
|
|
import java.io.IOException;
|
2022-06-09 19:18:16 +01:00
|
|
|
import java.util.Set;
|
2022-06-03 18:50:13 +01:00
|
|
|
import javax.sound.sampled.LineUnavailableException;
|
|
|
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
2022-05-30 19:36:18 +01:00
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
public class GameFrame extends JFrame{
|
|
|
|
|
2022-06-01 19:39:57 +01:00
|
|
|
MenuPanel menu;
|
|
|
|
GamePanel game;
|
2022-06-09 19:18:16 +01:00
|
|
|
SettingPanel settings;
|
|
|
|
CameraPanel main;
|
2022-05-30 19:36:18 +01:00
|
|
|
|
2022-05-30 19:46:53 +01:00
|
|
|
public GameFrame(){
|
2022-06-02 18:22:17 +01:00
|
|
|
try {
|
2022-06-09 19:18:16 +01:00
|
|
|
main = new CameraPanel();
|
2022-06-06 18:32:13 +01:00
|
|
|
main.setLayout(new CardLayout());
|
|
|
|
menu = new MenuPanel(main);
|
|
|
|
game = new GamePanel(main); //run GamePanel constructor
|
2022-06-09 19:18:16 +01:00
|
|
|
settings = new SettingPanel(main);
|
2022-06-06 18:32:13 +01:00
|
|
|
main.add(menu, "menu");
|
2022-06-09 19:18:16 +01:00
|
|
|
main.add(settings, "settings");
|
2022-06-06 18:32:13 +01:00
|
|
|
main.add(game, "game");
|
|
|
|
} catch (IOException | SpriteException | UnsupportedAudioFileException | LineUnavailableException e) {
|
2022-06-02 18:22:17 +01:00
|
|
|
// TODO: handle IO errors gracefully
|
|
|
|
// exceptions are raised when tiles are not found or are of incorrect dimensions
|
|
|
|
}
|
2022-06-06 18:32:13 +01:00
|
|
|
this.add(main);
|
2022-05-30 19:46:53 +01:00
|
|
|
this.setTitle("GUI is cool!"); //set title for frame
|
2022-06-03 18:09:59 +01:00
|
|
|
// 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) {}
|
2022-05-30 19:46:53 +01:00
|
|
|
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
|
|
|
}
|