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

📄 netwarpanel.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        unitPanel.add(property6ValueLabel, gridBagConstraints);

        justSpacingLabel1.setForeground(new java.awt.Color(255, 255, 255));
        justSpacingLabel1.setText("    ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 13;
        gridBagConstraints.gridy = 1;
        unitPanel.add(justSpacingLabel1, gridBagConstraints);

        justSpacingLabel2.setText("  ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 11;
        gridBagConstraints.gridy = 1;
        unitPanel.add(justSpacingLabel2, gridBagConstraints);

        justSpacingLabel3.setText("  ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 15;
        gridBagConstraints.gridy = 1;
        unitPanel.add(justSpacingLabel3, gridBagConstraints);

        unitViewHere.setBackground(java.awt.Color.lightGray);
        unitViewHere.setColumns(10);
        unitViewHere.setEditable(false);
        unitViewHere.setRows(9);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        unitPanel.add(unitViewHere, gridBagConstraints);

        optionSelectPane.addTab("Units", new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/UnitsBig.gif")), unitPanel, "Unit information and commands");

        basePanel.setLayout(new java.awt.GridBagLayout());

        basePanel.setBackground(java.awt.Color.lightGray);
        baseViewerTitleLabel.setFont(new java.awt.Font("Dialog", 1, 18));
        baseViewerTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        baseViewerTitleLabel.setText("Base Viewer");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        basePanel.add(baseViewerTitleLabel, gridBagConstraints);

        baseHealthLabel.setForeground(new java.awt.Color(255, 255, 255));
        baseHealthLabel.setText("Structural Integrity:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        basePanel.add(baseHealthLabel, gridBagConstraints);

        baseHealthBar.setBackground(new java.awt.Color(255, 255, 255));
        baseHealthBar.setMaximum(1000);
        baseHealthBar.setValue(1000);
        baseHealthBar.setString("1000 / 1000");
        baseHealthBar.setStringPainted(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        basePanel.add(baseHealthBar, gridBagConstraints);

        activeUnitsTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        activeUnitsTitleLabel.setText("Active Units:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        basePanel.add(activeUnitsTitleLabel, gridBagConstraints);

        totalUnitsTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        totalUnitsTitleLabel.setText("Total Built Units:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        basePanel.add(totalUnitsTitleLabel, gridBagConstraints);

        armyInfoTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        armyInfoTitleLabel.setText("Army Information:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        basePanel.add(armyInfoTitleLabel, gridBagConstraints);

        totalBuiltUnitsValueField.setBackground(java.awt.Color.lightGray);
        totalBuiltUnitsValueField.setColumns(5);
        totalBuiltUnitsValueField.setEditable(false);
        totalBuiltUnitsValueField.setForeground(new java.awt.Color(255, 255, 255));
        totalBuiltUnitsValueField.setText("0");
        totalBuiltUnitsValueField.setBorder(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        basePanel.add(totalBuiltUnitsValueField, gridBagConstraints);

        totalActiveUnitsValueField.setBackground(java.awt.Color.lightGray);
        totalActiveUnitsValueField.setColumns(5);
        totalActiveUnitsValueField.setEditable(false);
        totalActiveUnitsValueField.setForeground(new java.awt.Color(255, 255, 255));
        totalActiveUnitsValueField.setText("0");
        totalActiveUnitsValueField.setBorder(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        basePanel.add(totalActiveUnitsValueField, gridBagConstraints);

        ButtonList.setBackground(java.awt.Color.lightGray);
        addButtons();
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 3;
        basePanel.add(ButtonList, gridBagConstraints);

        optionSelectPane.addTab("Base", new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/BaseBig.gif")), basePanel, "View base info and create units");

        chatPanel.setLayout(new javax.swing.BoxLayout(chatPanel, javax.swing.BoxLayout.Y_AXIS));

        chatPanel.setBackground(java.awt.Color.lightGray);
        chatPanel.add(chatViewer1);

        optionSelectPane.addTab("Chat", new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/ChatBig.gif")), chatPanel, "Send and view messages from other player");

        systemPanel.setLayout(new java.awt.GridBagLayout());

        systemPanel.setBackground(java.awt.Color.lightGray);
        gFramesPerSecTitleLabel.setFont(new java.awt.Font("Dialog", 1, 14));
        gFramesPerSecTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        gFramesPerSecTitleLabel.setText("Graphics Frames/sec:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 24, 0, 24);
        systemPanel.add(gFramesPerSecTitleLabel, gridBagConstraints);

        uFramesPerSecTitleLabel.setFont(new java.awt.Font("Dialog", 1, 14));
        uFramesPerSecTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        uFramesPerSecTitleLabel.setText("Update Frames/sec:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        systemPanel.add(uFramesPerSecTitleLabel, gridBagConstraints);

        systemStatisticsTitleLabel.setFont(new java.awt.Font("Dialog", 1, 18));
        systemStatisticsTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
        systemStatisticsTitleLabel.setText("System Statistics");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        systemPanel.add(systemStatisticsTitleLabel, gridBagConstraints);

        gFPerSecValueField.setBackground(java.awt.Color.lightGray);
        gFPerSecValueField.setColumns(3);
        gFPerSecValueField.setEditable(false);
        gFPerSecValueField.setForeground(new java.awt.Color(255, 255, 255));
        gFPerSecValueField.setText("0");
        gFPerSecValueField.setBorder(null);
        gFPerSecValueField.setDisabledTextColor(java.awt.Color.lightGray);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        systemPanel.add(gFPerSecValueField, gridBagConstraints);

        uFPerSecValueField.setBackground(java.awt.Color.lightGray);
        uFPerSecValueField.setColumns(3);
        uFPerSecValueField.setEditable(false);
        uFPerSecValueField.setForeground(new java.awt.Color(255, 255, 255));
        uFPerSecValueField.setText("0");
        uFPerSecValueField.setBorder(null);
        uFPerSecValueField.setDisabledTextColor(java.awt.Color.lightGray);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        systemPanel.add(uFPerSecValueField, gridBagConstraints);

        optionSelectPane.addTab("System", new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/SystemBig.gif")), systemPanel, "Various information about the system");

        optionSelectPane.setSelectedIndex(1);

        add(optionSelectPane);

    }//GEN-END:initComponents

    /** This method should be called once per a game cycle.
     * It updates the "old" information of the NetwarPanel that must be done every game cycle.
     * This method should be called every game cycle to be assured of "up to date information".
     * This method updates information such as base health, the display of the unit in the Units Tab (what it looks like on the main screen), and the system statistics.
     * Some information will only be updated if you have the appropraite tab open (A feature that the user probably would not notice).
     */    
    public void updateDisplay(){
        if(firstUpdate){
            uDisp = new UnitDisplayer(unitViewHere, unitViewHere.getWidth(), unitViewHere.getHeight());
            firstUpdate = false;
            timer.start();
        }
        if (isPanelCurrentlySelected(0)) {
            try {
                go.getObjectWithID(selectedUnitID).center(uDisp.getTransform()); 
                go.getObjectWithID(selectedUnitID).draw(uDisp); 
                uDisp.recycle(); 
            }
            catch(NullPointerException e){
            }
        }
        else if (isPanelCurrentlySelected(1)) {
            // Base Refresh Methods here
            //numberCreatedUnitsValueLabel.setText("AmountofCreatedUnits");
           // numberLivingUnitsValueLabel.setText("AmountofLivingUnits");
            if(!netwar.game.Player.getLocal().baseDead())
                updateBaseHealth(netwar.game.Player.getLocal().getBase().getHealth());
        }
        else if (isPanelCurrentlySelected(2)) {
            // Chat Refresh Methods here
            // No Methods need to be used here yet (Maybe later)
        }
        else if (isPanelCurrentlySelected(3)) {
            // System Refresh Methods here
            gFPerSecValueField.setText(Integer.toString(netwar.utils.FPS.getG()));
            uFPerSecValueField.setText(Integer.toString(netwar.utils.FPS.getU()));
            
        }
    }
    
    /** This updates unit tab information.  It is to be called once a new unit is selected.
     * It displays all appropraite items needed when a new unit is selected (such as the units health, max health, name, properties, and picture).
     * @param properties This contains all the properties of the unit.  Health, Max Health, and Unit Name should always be included.
     * In addition, 6 other properties may be specified.
     * @param unitID This is the ID of the Unit which the properties pertain to.
     */    
    public void updateDisplay(String[][] properties, int unitID) {
        selectedUnitID = unitID;
        byte fieldSelector = 1;
        boolean maxHealthValueNotExist = true;
        boolean unitNameValueNotExist = true;
        for(int t = 0; t< properties[0].length; t++) {
            //System.out.println(properties[0][t] + "\t" + properties[1][t]);
            if(properties[0][t].equalsIgnoreCase("Max Health")){
                maxHealthValueLabel1.setText(properties[1][t]);
                maxHealthValueNotExist = false;
            }
            else if(properties[0][t].equalsIgnoreCase("Health")) {
                currentHealthValueLabel1.setText(properties[1][t]);
            }
            else if(properties[0][t].equalsIgnoreCase("Name")){
                unitSelectedNameLabel.setText(properties[1][t]);
                unitNameValueNotExist = false;
            }
            else {
                if(fieldSelector == 1){
                    property1TitleLabel.setText(properties[0][t]);
                    property1ValueLabel.setText(properties[1][t]);
                    fieldSelector++;
                }
                else if(fieldSelector == 2){
                    property2TitleLabel.setText(properties[0][t]);
                    property2ValueLabel.setText(properties[1][t]);
                    fieldSelector++;
                }
                else if(fieldSelector == 3){
                    property3TitleLabel.setText(properties[0][t]);
                    property3ValueLabel.setText(properties[1][t]);                    
                    fieldSelector++;
                }
                else if(fieldSelector == 4){
                    property4TitleLabel.setText(properties[0][t]);
                    property4ValueLabel.setText(properties[1][t]);
                    fieldSelector++;
                }
                else if(fieldSelector == 5){
                    property5TitleLabel.setText(properties[0][t]);
                    property5ValueLabel.setText(properties[1][t]);
                    fieldSelector++;
                }
                else if(fieldSelector == 6){
                    property6TitleLabel.setText(properties[0][t]);
                    property6ValueLabel.setText(properties[1][t]);
                    fieldSelector++;
                }
            }            
        }

⌨️ 快捷键说明

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