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

📄 netwarpanel.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        while(fieldSelector <= 6) {
            if(fieldSelector == 1){
                property1TitleLabel.setText("");
                property1ValueLabel.setText("");
                fieldSelector++;
            }
            else if(fieldSelector == 2){
                property2TitleLabel.setText("");
                property2ValueLabel.setText("");
                fieldSelector++;
            }
            else if(fieldSelector == 3){
                property3TitleLabel.setText("");
                property3ValueLabel.setText("");                    
                fieldSelector++;
            }
            else if(fieldSelector == 4){
                property4TitleLabel.setText("");
                property4ValueLabel.setText("");
                fieldSelector++;
            }
            else if(fieldSelector == 5){
                property5TitleLabel.setText("");
                property5ValueLabel.setText("");
                fieldSelector++;
            }
            else if(fieldSelector == 6){
                property6TitleLabel.setText("");
                property6ValueLabel.setText("");
                fieldSelector++;
            }
        }
        // If no MaxHealth value is given, the assumed value will be 1000
        if(maxHealthValueNotExist) {
            maxHealthValueLabel1.setText("1000");
        }
        
        if(unitNameValueNotExist) {
            unitSelectedNameLabel.setText("Name Doesn't Exist");
        }
            
        unitHealthBar.setMaximum(Integer.parseInt(maxHealthValueLabel1.getText()));
        unitHealthBar.setValue(Integer.parseInt(currentHealthValueLabel1.getText()));
        unitHealthBar.setString(currentHealthValueLabel1.getText() + " / " + maxHealthValueLabel1.getText());
//        changeUnitPicture(unitSelectedNameLabel.getText());

        // Debugging code...probably not needed any more
        // System.out.println("x" + maxHealthValueLabel1.getText() + "x");
        // System.out.println("x" + currentHealthValueLabel1.getText() + "x");
    }

    /** Tests if the unit ID of the specified unit is the same as the unit that is currently selected.
     * @param unitID The unit's ID that you want to test
     * @return If the unitID is different that the one being displayed on the Unit Pane, it returns true.
     * If the unitID is different than the one being displayed on the Unit Pane, it returns false.
     */    
    public boolean selectedUnitIDMatch(int unitID) {
        if(unitID != selectedUnitID)
            return false;
        return true;
    }
    
    /** This method will display the messages in the chat window that players send.
     * @param chatMessage This is the message that a player sent and needs to be displayed on the on the chat window.
     */    
    public void displayChat(String chatMessage){
	chatViewer1.displayChat(chatMessage);
	HexViewer.getHexViewer().displayString(chatMessage);
    }
    
/*    public void setStartBaseHealth(int initialBaseHealth) {  //Probably just delete this method
        baseHealthBar.setMaximum(initialBaseHealth);
        baseHealthBar.setValue(initialBaseHealth);
        baseHealthBar.setString(initialBaseHealth + " / " + initialBaseHealth);
    } */
    
    /** This updates the Base's Current Health on the Base Pane.
     * @param newCurrentValue The value for the base's life
     */    
    public void updateBaseHealth(int newCurrentValue) {
        if (newCurrentValue != baseHealth) {
            baseHealth = newCurrentValue;
            baseHealthBar.setValue(newCurrentValue);
            baseHealthBar.setString(newCurrentValue + " / " + baseHealthBar.getMaximum());
        }
    }
    
    /** This resets the unit tab.  This is to be called when no unit is selected on the hex viewer.
     */    
    public void noUnitSelected() {
        if (isPanelCurrentlySelected(0))
            uDisp.recycle();
        selectedUnitID = 0;
        deleteUnitTabFields();
    }
    
    /** Tests if the panelIndexNumber is the same as the one currently selected.
     * @param panelIndexNumber The index number of the tab that you want to test if it is currently selected.
     * 0 is the Unit Tab.
     * 1 is the Base Tab.
     * 2 is the Chat Tab.
     * 3 is the System Tab.
     * @return Returns true if panelIndexNumber is equal to the Index number of the tab currently selected.
     * Returns false otherwise.
     */    
    public boolean isPanelCurrentlySelected(int panelIndexNumber){
        if (panelIndexNumber == optionSelectPane.getSelectedIndex())
            return true;
        return false;        
    }
    
    /** This updates the health display on the Unit Pane.  It is only to be called if updateDisplay(String[][] properties, int unitID) has already been called for this unit.
     * @param newHealthValue The Health value for this unit.
     */    
    public void updateUnitHealth(int newHealthValue) {
        String newHealthValueString = Integer.toString(newHealthValue);
        currentHealthValueLabel1.setText(newHealthValueString);
        unitHealthBar.setValue(newHealthValue);
        unitHealthBar.setString(newHealthValueString + " / " + maxHealthValueLabel1.getText());
    }
    
/*    public void subtractFromUnitCounter() {
        activeUnitsAmountLabel.setText(Integer.toString(--activeUnits));
    }
 
    public void addToUnitCounter() {
        ++totalUnits;
        ++activeUnits;
        totalUnitsAmountLabel.setText(Integer.toString(totalUnits));
        activeUnitsAmountLabel.setText(Integer.toString(activeUnits));
        
    } */
    
    /** This increments the unit Total Unit Counter and the Current Unit Counter.
     * @param playerNumberOfTheUnitCreated This is the player number of the unit who created this unit.  This is so it only updates the player's display who created the unit.
     */    
    public void unitAdded(int playerNumberOfTheUnitCreated) {
        if(playerNumberOfTheUnitCreated == netwar.Netwar.nc.playerNumber) {
            currentArmyAmount++;
            totalArmyAmount++;
            totalActiveUnitsValueField.setText(Integer.toString(currentArmyAmount));
            totalBuiltUnitsValueField.setText(Integer.toString(totalArmyAmount));
        }
    }
    
    /** This decrements the ActiveUnits counter.
     * @param playerNumberOfTheUnitKilled This is the player number of the unit who was killed.  This is to ensure that only the player whose unit died gets their Active Units Counter Decremented.
     */    
    public void unitKilled(int playerNumberOfTheUnitKilled) {
        if(playerNumberOfTheUnitKilled == netwar.Netwar.nc.playerNumber) {
            currentArmyAmount--;
            totalActiveUnitsValueField.setText(Integer.toString(currentArmyAmount));
        }
    }
    private void deleteUnitTabFields() {
        property1TitleLabel.setText("");
        property1ValueLabel.setText("");
        property2TitleLabel.setText("");
        property2ValueLabel.setText("");
        property3TitleLabel.setText("");
        property3ValueLabel.setText("");
        property4TitleLabel.setText("");
        property4ValueLabel.setText("");
        property5TitleLabel.setText("");
        property5ValueLabel.setText("");
        property6TitleLabel.setText("");
        property6ValueLabel.setText("");
        maxHealthValueLabel1.setText("");
        currentHealthValueLabel1.setText("");
        unitSelectedNameLabel.setText("");
        unitHealthBar.setValue(0);
        unitHealthBar.setString("Health");
 //       unitPictureLabel.setIcon(nothingPic);
    }
    private void addButtons() {
        for(int t =0; t < Netwar.netwar.pset.unitSet.getNumberOfTypes(); t++) {
            javax.swing.JButton b = new javax.swing.JButton();
            b.setForeground(new java.awt.Color(255, 255, 255));
            b.setText("Construct " + Netwar.netwar.pset.unitSet.getFriendlyName(t));
            b.addActionListener(new customActionListener(t));
            ButtonList.add(b);
        }
    }
 /*   private void changeUnitPicture(String picture) {  // These will return (I hope)
        if (picture.equalsIgnoreCase("UnitDefault"))
            unitPictureLabel.setIcon(classicPlanePic);
        else if (picture.equalsIgnoreCase("StealthFighter"))
            unitPictureLabel.setIcon(stealthPlanePic);
         else if (picture.equalsIgnoreCase("LMGHunter"))
            unitPictureLabel.setIcon(lmgHunterPic);
        else
            unitPictureLabel.setIcon(basePic);
    } */
//    private int totalUnits = 0;
//    private int activeUnits = 0;
    private int currentArmyAmount = 0;
    private int totalArmyAmount = 0;
    private netwar.game.GameObject go;
    private UnitDisplayer uDisp; 
    private int baseHealth = 1000;
    private int selectedUnitID = 0;
    private boolean firstUpdate = true;
//    private javax.swing.ImageIcon classicPlanePic = new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/Classic Plane.jpg"));
//    private javax.swing.ImageIcon stealthPlanePic = new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/Stealth Plane.jpg"));
//    private javax.swing.ImageIcon lmgHunterPic = new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/LMGHunter.jpg"));
//    private javax.swing.ImageIcon basePic = new javax.swing.ImageIcon(getClass().getResource("/netwar/media/gui/Base Picture.gif"));
//   private javax.swing.ImageIcon nothingPic = new javax.swing.ImageIcon();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField gFPerSecValueField;
    private javax.swing.JLabel maxHealthTitleLabel;
    private netwar.gui.MinimapViewer minimapViewer1;
    private javax.swing.JLabel selectedUnitLabel;
    private javax.swing.JProgressBar unitHealthBar;
    private javax.swing.JLabel currenthealthTitleLabel;
    private netwar.gui.ChatViewer chatViewer1;
    private javax.swing.JLabel baseHealthLabel;
    private javax.swing.JLabel totalUnitsTitleLabel;
    private javax.swing.JLabel activeUnitsTitleLabel;
    private javax.swing.JLabel property6ValueLabel;
    private javax.swing.JLabel property4ValueLabel;
    private javax.swing.JPanel unitPanel;
    private javax.swing.JLabel property2ValueLabel;
    private javax.swing.JTextField totalBuiltUnitsValueField;
    private javax.swing.JLabel property6TitleLabel;
    private javax.swing.JLabel property4TitleLabel;
    private javax.swing.JTabbedPane optionSelectPane;
    private javax.swing.JLabel property2TitleLabel;
    private javax.swing.JTextArea unitViewHere;
    private javax.swing.JLabel justSpacingLabel3;
    private javax.swing.JLabel justSpacingLabel2;
    private javax.swing.JLabel justSpacingLabel1;
    private javax.swing.JLabel systemStatisticsTitleLabel;
    private javax.swing.JLabel armyInfoTitleLabel;
    private javax.swing.JProgressBar baseHealthBar;
    private javax.swing.JPanel basePanel;
    private javax.swing.JTextField uFPerSecValueField;
    private javax.swing.JLabel unitViewLabel;
    private javax.swing.JLabel uFramesPerSecTitleLabel;
    private javax.swing.JLabel unitSelectedNameLabel;
    private javax.swing.JLabel property5ValueLabel;
    private javax.swing.JLabel property3ValueLabel;
    private javax.swing.JLabel property1ValueLabel;
    private javax.swing.JLabel baseViewerTitleLabel;
    private javax.swing.JLabel gFramesPerSecTitleLabel;
    private javax.swing.JLabel unitHealthTitleLabel;
    private javax.swing.JLabel property5TitleLabel;
    private javax.swing.JLabel property3TitleLabel;
    private javax.swing.JLabel currentHealthValueLabel1;
    private javax.swing.JLabel property1TitleLabel;
    private javax.swing.JPanel systemPanel;
    private javax.swing.JPanel ButtonList;
    private javax.swing.JLabel maxHealthValueLabel1;
    private javax.swing.JTextField totalActiveUnitsValueField;
    private javax.swing.JPanel chatPanel;
    private javax.swing.JLabel propertiesLabel;
    // End of variables declaration//GEN-END:variables

    /** This class is an extention of ActionListener so that you can pass an integer to it
     */
    private class customActionListener implements java.awt.event.ActionListener {
        private int index;
        public customActionListener(int t) {
            index = t;
        }
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            Command.pendingCommands.enqueue(new Command(1, netwar.Netwar.nc.playerNumber, null,index, 0));
        }
    }
    
    public void actionPerformed(ActionEvent e) {
        minimapViewer1.repaint();
    }

    protected void finalize() throws java.lang.Throwable {
        timer.stop();
        super.finalize();
    }
    
}

⌨️ 快捷键说明

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