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

📄 mainframe.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.form.gui.swing.game.form;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;

import jm.form.gui.swing.game.action.MonsterAction;
import jm.form.gui.swing.game.form.layout.MapPanel;
import jm.form.gui.swing.game.system.SystemManager;
import jm.form.gui.swing.game.util.Utils;
import jm.form.gui.swing.game.util.model.BaseFrame;
import jm.framework.gui.Message;
import jm.framework.gui.ReLoad;
import jm.framework.gui.container.JMButtonPanel;
import jm.framework.gui.module.JMList;
import jm.framework.gui.module.JMListModel;
import jm.util.JMVector;
import jm.entity.game.base.EMJ0Y0100;
import jm.entity.game.base.EMJ0Y0200;

/**
 * <p>游戏主画面</p>
 *
 * <p>Copyright: Copyright (c) 2004-2006</p>
 *
 * <p>Company: 1SHome</p>
 *
 * <p>@author Spook</p>
 *
 * @since 1.3
 * @see JDK 1.5.0.6
 */
public class MainFrame extends BaseFrame implements ReLoad, Message, MonsterAction {
    private BorderLayout borderLayout1 = new BorderLayout();
    private JSplitPane BackSplitPane = new JSplitPane();
    private JPanel PlayerPanel = new JPanel();
    private JSplitPane TitleSplitPane = new JSplitPane();
    private JPanel CommandPanel = new JPanel();
    private GridLayout gridLayout1 = new GridLayout();
    private JMButtonPanel TopCommandPanel = new JMButtonPanel(3);
    private JMButtonPanel BottomCommandPanel = new JMButtonPanel(3);
    private JSplitPane FightSplitPane = new JSplitPane();
    private JSplitPane ContralSplitPane = new JSplitPane();
    private JScrollPane MonsterPanel = new JScrollPane();
//    private JPanel ContralPanel = new JPanel();
//    private JButton UpButton = new JButton(new JMIcon("image/game/contral/up.gif"));
//    private JButton DownButton = new JButton(new JMIcon("image/game/contral/down.gif"));
//    private JButton LeftButton = new JButton(new JMIcon("image/game/contral/left.gif"));
//    private JButton RightButton = new JButton(new JMIcon("image/game/contral/right.gif"));
    private JScrollPane MainScrollPane = new JScrollPane();
    private MapPanel mapPanel = new MapPanel();
    private JSplitPane PlayersSplitPane = new JSplitPane();
    private JMList MonstersList = new JMList();
    private JPanel PlayerlistPanel = new JPanel();
    private JPanel BottomPanel = new JPanel();
    private JSplitPane MainSplitPane = new JSplitPane();
    private JScrollPane MessageScrollPane = new JScrollPane();
    private JTextArea Message = new JTextArea();
    private BorderLayout borderLayout2 = new BorderLayout();
    private GridLayout gridLayout2 = new GridLayout();

    public MainFrame () {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit () throws Exception {
        this.setSize(new Dimension(400 + BZ_WITH, 380 + BZ_HEIGHT));
        int SplitDividerSize = 5;
        BackSplitPane.setContinuousLayout(true);
        BackSplitPane.setOneTouchExpandable(true);
        BackSplitPane.setDividerLocation(50);
        BackSplitPane.setDividerSize(SplitDividerSize);

        TitleSplitPane.setContinuousLayout(true);
        //TitleSplitPane.setOneTouchExpandable(true);
        TitleSplitPane.setDividerLocation(275);
        TitleSplitPane.setDividerSize(0);

        MainSplitPane.setContinuousLayout(true);
        MainSplitPane.setOneTouchExpandable(true);
        MainSplitPane.setDividerLocation(255);
        MainSplitPane.setDividerSize(SplitDividerSize);

        FightSplitPane.setContinuousLayout(true);
        FightSplitPane.setOneTouchExpandable(true);
        FightSplitPane.setDividerLocation(94);
        FightSplitPane.setDividerSize(SplitDividerSize);

        ContralSplitPane.setContinuousLayout(true);
//        ContralSplitPane.setOneTouchExpandable(true);
        ContralSplitPane.setDividerLocation(0);
        ContralSplitPane.setDividerSize(0);

        PlayersSplitPane.setContinuousLayout(true);
        PlayersSplitPane.setOneTouchExpandable(true);
        PlayersSplitPane.setDividerLocation(200);
        PlayersSplitPane.setDividerSize(SplitDividerSize);

        getContentPane().setLayout(borderLayout1);
        CommandPanel.setLayout(gridLayout1);
        gridLayout1.setRows(2);
        ContralSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
//        UpButton.setPreferredSize(new Dimension(23, 22));
//        UpButton.addActionListener(new ActionListener() {
//            public void actionPerformed (ActionEvent actionEvent) {
//                UpButton_actionPerformed(actionEvent);
//            }
//        });

        /**
         * 怪物列表
         */
        MonstersList.addMouseListener(new MouseAdapter() {
            public void mouseClicked (MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON3 &&
                    ((JMListModel) MonstersList.getModel()).size() > 0) {
                    //显示弹出菜单
                    RightMenu.show(MonstersList, e.getX(), e.getY());
                }
            }
        }
        );

        //查看
        JMenuItem Look = new JMenuItem("查看");
        Look.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed (MouseEvent e) {
                selectMonster();
            }
        });
        RightMenu.add(Look);
        //交谈
        JMenuItem Talk = new JMenuItem("交谈");
        Talk.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed (MouseEvent e) {
                selectMonster();
            }
        });
        RightMenu.add(Talk);
        //战斗
        JMenuItem Fight = new JMenuItem("战斗");
        Fight.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed (MouseEvent e) {
                fightWithMonster();
            }
        });
        RightMenu.add(Fight);
        ///////////////////////////////////////////////////////////////
//        ContralPanel.setLayout(gridLayout2);
        MainScrollPane.setBorder(null);
        MonsterPanel.setBorder(null);
        PlayersSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        MainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        BottomPanel.setLayout(borderLayout2);
        Message.setForeground(Color.blue);
        Message.setEditable(false);
        Message.setText("Let\'s GO.");
        this.getContentPane().add(BackSplitPane, java.awt.BorderLayout.CENTER);
        BackSplitPane.add(TitleSplitPane, JSplitPane.TOP);
        TitleSplitPane.add(PlayerPanel, JSplitPane.LEFT);
        TitleSplitPane.add(CommandPanel, JSplitPane.RIGHT);
        CommandPanel.add(TopCommandPanel);
        CommandPanel.add(BottomCommandPanel);
        BackSplitPane.add(FightSplitPane, JSplitPane.BOTTOM);
//        ContralSplitPane.add(ContralPanel, JSplitPane.TOP);
        ContralSplitPane.add(PlayersSplitPane, JSplitPane.BOTTOM);
        FightSplitPane.add(MainSplitPane, JSplitPane.RIGHT);
        PlayersSplitPane.add(MonsterPanel, JSplitPane.TOP);
        MonsterPanel.getViewport().add(MonstersList);
        PlayersSplitPane.add(PlayerlistPanel, JSplitPane.BOTTOM);
        FightSplitPane.add(ContralSplitPane, JSplitPane.LEFT);
        BottomPanel.add(MessageScrollPane, java.awt.BorderLayout.CENTER);
        MainSplitPane.add(MainScrollPane, JSplitPane.TOP);
        MainSplitPane.add(BottomPanel, JSplitPane.BOTTOM);
        MainScrollPane.getViewport().add(mapPanel);
        MessageScrollPane.getViewport().add(Message);
//        ContralPanel.add(LeftButton, null);
//        ContralPanel.add(UpButton, null);
//        ContralPanel.add(DownButton, null);
//        ContralPanel.add(RightButton, null);
        BackSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);

        ////////////////////////////
        loadMonsters(null);
    }

    private JPopupMenu RightMenu = new JPopupMenu();

    /////////////////////////////////////////////////////////////
    //修正地图怪物列表
    //单机本地随机生成
    //联机同步数据
    private JMVector<EMJ0Y0200> Monsters_ = new JMVector<EMJ0Y0200>();
    public void loadMonsters (EMJ0Y0100 currentMapElement) {
        EMJ0Y0200 temp = new EMJ0Y0200();
        for (int i = 0; i < 10; i++){
            temp.setName("AAA");
            addMonster(temp);
        }
        MonstersList.setSelectedIndex(0);
    }

    public JMVector<EMJ0Y0200> getMonsters () {
        return Monsters_;
    }

    public void addMonster (EMJ0Y0200 monster) {
        ((JMListModel) MonstersList.getModel()).addElement(monster.getName());
        Monsters_.add(monster); ;
    }

    public void removeMonster (int index) {
        ((JMListModel) MonstersList.getModel()).removeElementAt(index);
        Monsters_.remove(index);
    }

    public void selectMonster () {
        int select = MonstersList.getSelectedIndex();
        setMessage("" + select);
    }

    /**
     * 攻击怪物
     */
    public void fightWithMonster () {
        this.setVisible(false);
        try {
            FightDialog fight = new FightDialog();
            fight.setOwner(this);
            fight.setTitle("战斗");
//            fight.reLoad();

            fight.actionPerformed(null, null);
            fight.init("", "");
            Utils.showAtCenterInScreen(fight);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        this.setVisible(true);
    }
    ////////////////////////////////////////////////////////////////////////////
//    /**
//     * 装载业务画面
//     * @param frameInfo MenuFrameBean
//     * @return boolean
//     */
//    public boolean loadFrame (MenuFrameBean frameInfo) {
//        try {
//            BaseFrame bf = (BaseFrame) Class.forName(
//                    frameInfo.getFrameBean().getGamenPath()).newInstance();
//            bf.setTitle(TITLE + frameInfo.getFrameBean().getGamenName());
//            if (bf instanceof ReLoad) {
//                ((ReLoad) bf).reLoad();
//            }
//            bf.init(SY010000.class.getName(), "");
//            Utils.showAtCenterInScreen(bf);
//        } catch (Exception exception) {
//            exception.printStackTrace();
//            setMessage(SystemCommandKeys.SYSTEM_WARING);
//            return false;
//        }
//        return true;
//    }
//
//    /**
//     * 装载业务画面
//     * @param frameInfo MenuFrameBean
//     * @return boolean
//     */
//    public boolean loadDialog (MenuFrameBean frameInfo) {
//        try {
//            BaseDialog bd = (BaseDialog) Class.forName(
//                    frameInfo.getFrameBean().getGamenPath()).newInstance();
//            bd.setOwner(mainBackGround);
//            bd.setTitle(frameInfo.getFrameBean().getGamenName());
////            bd.setTitle(TITLE + frameInfo.getFrameBean().getGamenName());
//            if (bd instanceof ReLoad) {
//                ((ReLoad) bd).reLoad();
//            }
//
//            bd.actionPerformed(frameInfo, null);
//            bd.init(SY010000.class.getName(), "");
//            Utils.showAtCenterInScreen(bd);
//        } catch (Exception exception) {
//            exception.printStackTrace();
//            setMessage(SystemCommandKeys.SYSTEM_WARING + " " + exception.getMessage());
//            return false;
//        }
//        return true;
//    }

    //static initializer for setting look & feel
    static {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
        }
    }

    public boolean init (String asAppId, String asInitOption) {
        return false;
    }

    public boolean queryClose () {
        SystemManager.getInstance().exit();
        return true;
    }

    public boolean reLoad () {
        return true;
    }

    public void setMessage (String message) {
        Message.select(0,0);
        Message.insert(message+"\n",0);
    }
}

⌨️ 快捷键说明

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