⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameframe.java

📁 龙与地下城游戏(小型)的设计与实现。主要是随机产生地牢
💻 JAVA
字号:
package dungeonsanddragons.game;import java.awt.BorderLayout;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JFrame;import javax.swing.JPanel;/** * Class to handle the main game frame. *  * No need to change anything here!! * @author Sandra Nilsson */public class GameFrame extends JFrame implements WindowListener {    public final static int ROOM_SIZE = 70;    public final static int SIZE = 10;    GamePanel game;    GameStatus status;        /** Creates and initializes a new instance of DrawerFrame */    public GameFrame(String title) {        super(title);        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        this.addWindowListener(this);        this.setIgnoreRepaint(true);        this.setResizable(false);                setSize(ROOM_SIZE*SIZE+5, ROOM_SIZE*SIZE+32);        setLocationRelativeTo(null);        init();    }    /**Initializes the frame*/    private void init() {        JPanel mainPanel = new JPanel(new BorderLayout());                status = new GameStatus();        status.setVisible(true);        game = new GamePanel(status);                mainPanel.add(game, BorderLayout.CENTER);        this.getContentPane().add(mainPanel);    }    /**     * Set this frame visible (showing) and make sure that the board is drawn at the same time.     * Overrides setVisible method in JFrame     * @param visible     *      */    public void setVisible(boolean visible) {        super.setVisible(visible);        game.draw();    }    /**     * Mehtod that is called when the window is opened     * @param e the event     */    public void windowOpened(WindowEvent e) {        game.draw();    }    /**     * Mehtod that is called when the window is back from beeing iconified     * @param e the event     */    public void windowDeiconified(WindowEvent e) {        game.draw();    }    /**     * Mehtod that is called when the window is activiated     * @param e the event     */    public void windowActivated(WindowEvent e) {        game.draw();    }    /**     * Mehtod that is called when the window is on its way to be closed (before it clises)     * @param e the event     */    public void windowClosing(WindowEvent e) {        status.setVisible(false);    }    /**     * Mehtod that is called when the window is closed     * @param e the event     */    public void windowClosed(WindowEvent e) {    }    /**     * Mehtod that is called when the window is iconified     * @param e the event     */    public void windowIconified(WindowEvent e) {    }    /**     * Mehtod that is called when the window is deactivated     * @param e the event     */    public void windowDeactivated(WindowEvent e) {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -