List of usage examples for javax.swing JComboBox getParent
public Container getParent()
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; }/* w ww . j a va2 s. 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(); } } }