Example usage for javax.swing JPanel getComponent

List of usage examples for javax.swing JPanel getComponent

Introduction

In this page you can find the example usage for javax.swing JPanel getComponent.

Prototype

public Component getComponent(int n) 

Source Link

Document

Gets the nth component in this container.

Usage

From source file:com.game.ui.views.ItemPanel.java

public void persistRingData(String name, JPanel panel) {
    String incHealth = ((JTextField) panel.getComponent(4)).getText();
    String incArmour = ((JTextField) panel.getComponent(6)).getText();
    String incAttack = ((JTextField) panel.getComponent(8)).getText();
    if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(incHealth) && StringUtils.isNotBlank(incArmour)
            && StringUtils.isNotBlank(incAttack)) {
        int position = GameUtils.getPositionOfRingItem(name);
        if (GameBean.ringDetails == null) {
            GameBean.ringDetails = new ArrayList<>();
        }/*  w  ww  .  java  2  s .  com*/
        if (position != -1) {
            GameBean.ringDetails.remove(position);
        }
        Ring ring = new Ring();
        ring.setName(name);
        ring.setIncArmour(Integer.parseInt(incArmour));
        ring.setIncHealth(Integer.parseInt(incHealth));
        ring.setIncAttack(Integer.parseInt(incAttack));
        GameBean.ringDetails.add(ring);
        try {
            GameUtils.writeItemsToXML(GameBean.ringDetails, Configuration.PATH_FOR_RINGS);
            validationMess.setText("Saved Successfully..");
            validationMess.setVisible(true);
            if (position == -1) {
                comboBox.removeActionListener(this);
                comboBox.addItem(name);
                comboBox.setSelectedItem(name);
                comboBox.addActionListener(this);
            }
            TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
            if (tileInfo == null) {
                tileInfo = new TileInformation();
            }
            tileInfo.setRing(ring);
            GameBean.mapInfo.getPathMap().put(location, tileInfo);
            chkBox.setSelected(true);
        } catch (Exception e) {
            validationMess.setText("Some error occured...");
            e.printStackTrace();
            validationMess.setVisible(true);
        }
    } else {
        validationMess.setText("Pls enter all the fields or pls choose a weapon from the drop down");
        validationMess.setVisible(true);
    }
}

From source file:com.game.ui.views.ItemPanel.java

public void persistArmourData(String name, JPanel panel) {
    String armourPts = ((JTextField) panel.getComponent(4)).getText();
    Object temp = armourBox.getSelectedItem();
    String armourType = null;/*from   ww w. java2 s. c om*/
    if (temp != null)
        armourType = temp.toString();
    if (StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(name)
            && StringUtils.isNotBlank(armourType)) {
        int position = GameUtils.getPositionOfArmourItem(name);
        if (position != -1) {
            GameBean.armourDetails.remove(position);
        }
        if (GameBean.armourDetails == null) {
            GameBean.armourDetails = new ArrayList<>();
        }
        Armour armour = new Armour();
        armour.setName(name);
        armour.setArmourPts(Integer.parseInt(armourPts));
        armour.setArmourType(armourType);
        GameBean.armourDetails.add(armour);
        try {
            GameUtils.writeItemsToXML(GameBean.armourDetails, Configuration.PATH_FOR_ARMOURS);
            validationMess.setText("Saved Successfully..");
            validationMess.setVisible(true);
            if (position == -1) {
                comboBox.removeActionListener(this);
                comboBox.addItem(name);
                comboBox.setSelectedItem(name);
                comboBox.addActionListener(this);
            }
            TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
            if (tileInfo == null) {
                tileInfo = new TileInformation();
            }
            tileInfo.setArmour(armour);
            GameBean.mapInfo.getPathMap().put(location, tileInfo);
            chkBox.setSelected(true);
        } catch (Exception e) {
            validationMess.setText("Some error occured...");
            e.printStackTrace();
            validationMess.setVisible(true);
        }
    } else {
        validationMess.setText("Pls enter all the fields or pls choose a weapon from the drop down");
        validationMess.setVisible(true);
    }
}

From source file:com.game.ui.views.CharachterEditorPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JComboBox comboBox = (JComboBox) ae.getSource();
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (GameCharacter enemy : GameBean.enemyDetails) {
            if (enemy.getName().equalsIgnoreCase(name)) {
                ((JTextField) panel.getComponent(2)).setText(enemy.getName());
                ((JTextField) panel.getComponent(4)).setText(enemy.getImagePath());
                ((JTextField) panel.getComponent(6)).setText(new Integer(enemy.getHealth()).toString());
                ((JTextField) panel.getComponent(8)).setText(new Integer(enemy.getAttackPts()).toString());
                ((JTextField) panel.getComponent(10)).setText(new Integer(enemy.getArmor()).toString());
                ((JTextField) panel.getComponent(12)).setText(new Integer(enemy.getAttackRange()).toString());
                ((JTextField) panel.getComponent(14)).setText(new Integer(enemy.getMovement()).toString());
                return;
            }/*www  .j av a  2s  .  c o  m*/
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        int indexOfBtn = btn.getAccessibleContext().getAccessibleIndexInParent();
        String name = ((JTextField) panel.getComponent(2)).getText();
        String image = ((JTextField) panel.getComponent(4)).getText();
        String health = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        String armourPts = ((JTextField) panel.getComponent(10)).getText();
        String attackRnge = ((JTextField) panel.getComponent(12)).getText();
        String movement = ((JTextField) panel.getComponent(14)).getText();
        System.out.println("Index : " + indexOfBtn);
        JLabel message = ((JLabel) this.getComponent(5));
        message.setText("");
        message.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health)
                && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement)) {
            message.setVisible(false);
            GameCharacter character = new GameCharacter();
            character.setName(name);
            character.setAttackPts(Integer.parseInt(attackPts));
            character.setAttackRange(Integer.parseInt(attackRnge));
            character.setHealth(Integer.parseInt(health));
            character.setImagePath(image);
            character.setMovement(Integer.parseInt(movement));
            character.setArmor(Integer.parseInt(armourPts));
            boolean characterAlrdyPresent = false;
            for (int i = 0; i < GameBean.enemyDetails.size(); i++) {
                GameCharacter charFromList = GameBean.enemyDetails.get(i);
                if (charFromList.getName().equalsIgnoreCase(name)) {
                    GameBean.enemyDetails.remove(i);
                    GameBean.enemyDetails.add(i, character);
                    characterAlrdyPresent = true;
                }
            }
            if (!characterAlrdyPresent) {
                GameBean.enemyDetails.add(character);
            }
            try {
                GameUtils.writeCharactersToXML(GameBean.enemyDetails, Configuration.PATH_FOR_ENEMY_CHARACTERS);
                message.setText("Saved Successfully..");
                message.setVisible(true);
                if (!characterAlrdyPresent) {
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setEnemy(character);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("CharachterEditorPanel : actionPerformed() : Some error occured " + e);
                e.printStackTrace();
            }

        } else {
            message.setText("Pls enter all the fields or pls choose a character from the drop down");
            message.setVisible(true);
            this.revalidate();
        }
    }
}

From source file:com.game.ui.views.WeaponEditorPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (Item item : GameBean.weaponDetails) {
            if (item instanceof Weapon) {
                Weapon weapon = (Weapon) item;
                if (weapon.getName().equalsIgnoreCase(name)) {
                    ((JTextField) panel.getComponent(2)).setText(name);
                    ((JComboBox) panel.getComponent(4)).setSelectedItem(weapon.getWeaponType());
                    ((JTextField) panel.getComponent(6)).setText(Integer.toString(weapon.getAttackRange()));
                    ((JTextField) panel.getComponent(8)).setText(Integer.toString(weapon.getAttackPts()));
                    return;
                }/*from www. j a  v  a2s .c  o  m*/
            }
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        String name = ((JTextField) panel.getComponent(2)).getText();

        String weaponType = (String) (((JComboBox) panel.getComponent(4)).getSelectedItem());
        String attackRnge = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        //            JLabel message = ((JLabel) this.getComponent(5));
        validationMess.setText("");
        validationMess.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(weaponType)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(attackPts)) {
            validationMess.setVisible(false);
            Weapon weapon = new Weapon();
            weapon.setName(name);
            ;
            weapon.setAttackRange(Integer.parseInt(attackRnge));
            weapon.setAttackPts(Integer.parseInt(attackPts));
            weapon.setWeaponType(weaponType);
            boolean weaponAlrdyPresent = false;
            int position = GameUtils.getPositionOfWeaponItem(name);
            if (GameBean.weaponDetails == null) {
                GameBean.weaponDetails = new ArrayList<Item>();
            }
            if (position != -1) {
                GameBean.weaponDetails.remove(position);
            }
            GameBean.weaponDetails.add(weapon);
            try {
                GameUtils.writeItemsToXML(GameBean.weaponDetails, Configuration.PATH_FOR_WEAPONS);
                validationMess.setText("Saved Successfully..");
                validationMess.setVisible(true);
                if (!weaponAlrdyPresent) {
                    comboBox.removeActionListener(this);
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                    comboBox.addActionListener(this);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setWeapon(weapon);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("WeaponEditorPanel : actionPerformed() : Some error occured " + e);
            }

        } else {
            validationMess.setText("Pls enter all the fields or pls choose a weapon from the drop down");
            validationMess.setVisible(true);
            panel.revalidate();
        }
    }
}

From source file:com.game.ui.views.ItemPanel.java

public void getRingDetailForName(String name, JPanel panel) {
    for (Item item : GameBean.ringDetails) {
        Ring ring = (Ring) item;//  ww w . j a  va  2  s  . co  m
        if (ring.getName().equalsIgnoreCase(name)) {
            ((JTextField) panel.getComponent(2)).setText(name);
            ((JTextField) panel.getComponent(4)).setText("" + ring.getIncHealth());
            ((JTextField) panel.getComponent(6)).setText(Integer.toString(ring.getIncArmour()));
            ((JTextField) panel.getComponent(8)).setText(Integer.toString(ring.getIncAttack()));
            return;
        }
    }
}

From source file:com.game.ui.views.ItemPanel.java

public void getPotionDetailForName(String name, JPanel panel) {
    for (Item item : GameBean.potionDetails) {
        Potion potion = (Potion) item;/*from   w  w w  .j a  v a 2 s  .c o  m*/
        if (potion.getName().equalsIgnoreCase(name)) {
            ((JTextField) panel.getComponent(2)).setText(name);
            ((JTextField) panel.getComponent(4)).setText("" + potion.getPotionPts());
            return;
        }
    }
}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

private ChartPanel getChartPanel(int i, int j) {
    JPanel chartContainer = (JPanel) ((JPanel) graphix.getComponent(i)).getComponent(j);
    int count = 0;
    while (count < chartContainer.getComponentCount()) {
        if (chartContainer.getComponent(count) instanceof ChartPanel) {
            return (ChartPanel) chartContainer.getComponent(count);
        } else {/*from   w w w  .j  a v  a  2s  .  c om*/
            count++;
        }
    }
    return null;
}

From source file:com.game.ui.views.ItemPanel.java

public void getArmourDetailForName(String name, JPanel panel) {
    for (Item item : GameBean.armourDetails) {
        Armour armour = (Armour) item;//from   ww  w .j a v  a  2s  . co m
        if (armour.getName().equalsIgnoreCase(name)) {
            ((JTextField) panel.getComponent(2)).setText(name);
            ((JTextField) panel.getComponent(4)).setText("" + armour.getArmourPts());
            String temp = armour.getArmourType();
            for (int i = 0; i < Configuration.armourTypes.length; i++) {
                if (temp.equalsIgnoreCase(Configuration.armourTypes[i])) {
                    armourBox.setSelectedIndex(i);
                }
            }
            return;
        }
    }
}

From source file:com.game.ui.views.ItemPanel.java

public void getTreasureDetailForName(String name, JPanel panel) {
    for (Item item : GameBean.treasureDetails) {
        Treasure treasure = (Treasure) item;
        if (treasure.getName().equalsIgnoreCase(name)) {
            ((JTextField) panel.getComponent(2)).setText(name);
            ((JTextField) panel.getComponent(4)).setText("" + treasure.getValue());
            return;
        }//from   w w w  .  ja  v  a2  s.co m
    }
}

From source file:logdruid.ui.chart.GraphPanel.java

public void resetTimePeriod(JPanel panel_2) {
    startDateJSpinner = (JSpinner) panel_2.getComponent(2);
    endDateJSPinner = (JSpinner) panel_2.getComponent(3);
    minimumDate = mineResultSet.getStartDate();
    maximumDate = mineResultSet.getEndDate();
    if (minimumDate != null)
        startDateJSpinner.setValue(minimumDate);
    if (maximumDate != null)
        endDateJSPinner.setValue(maximumDate);
}