Original Post
I'm using a string array to create a new JComboBox based on certain data that CAN be changed. When it's changed I try and create a new JComboBox with the same JComboBox, just different data.
However, it doesn't change, am I missing something?
It's for a char chooser for World of WarCraft
Just messing around, here is the class if I explained it bad:
public class Wowchooser extends JApplet implements ActionListener {
//Components
JComboBox raceComboBox;
JComboBox classComboBox;
//Information
String faction = "";
String[] allianceRaces = {"Dwarf", "Gnome", "Human", "Night Elf"};
String[] hordeRaces = {"Orcs", "Tauren", "Trolls", "Undead"};
String[] raceClasses;
public Wowchooser() throws HeadlessException {
}
public void init() {
//Set layout manager to null
this.getContentPane().setLayout(null);
//Get the users faction
while (!faction.toLowerCase().equals("alliance") &&
!faction.toLowerCase().equals("horde")) {
faction = JOptionPane.showInputDialog("Alliance or Horde?");
if (!faction.toLowerCase().equals("alliance") &&
!faction.toLowerCase().equals("horde")) {
JOptionPane.showMessageDialog(null, "Invalid choice, Alliance or Horde only!");
}
}
//Create a new combobox with info based on faction
if(faction.toLowerCase().equals("alliance")) {
raceComboBox = new JComboBox(allianceRaces);
}
else if(faction.toLowerCase().equals("horde")) {
raceComboBox = new JComboBox(hordeRaces);
}
//Set the combobox in a position regardless of faction
raceComboBox.setBounds(new Rectangle(50, 30, 100, 20));
raceComboBox.addActionListener(this);
this.getContentPane().add(raceComboBox, null);
}
public void paint(Graphics g) {
//Application width/height, also can be used for double buffering
Dimension d = getSize();
//Paint any components
super.paint(g);
//Draw the rest of the stuff
g.drawString("World of WarCraft Char Chooser", d.width/2-77, 15);
g.drawString("Race: ", 15, 43);
g.drawLine(0, 26, d.width, 26);
}
public void actionPerformed(ActionEvent e) {
//Get the source, and selected and set the class string based on race
JComboBox cb = (JComboBox) e.getSource();
String selected = (String) cb.getSelectedItem();
setClassString(selected);
}
public void setClassString(String r) {
//Dwarf
if(r.toLowerCase().equals("dwarf")) {
String[] classes = {"Hunter", "Mage", "Paladin", "Priest", "Rogue", "Warrior"};
raceClasses = classes;
}
//Gnome
else if(r.toLowerCase().equals("gnome")) {
String[] classes = {"Mage", "Rogue", "Warlock", "Warrior"};
raceClasses = classes;
}
//Human
else if(r.toLowerCase().equals("human")) {
String[] classes = {"Mage", "Paladin", "Priest", "Rogue", "Warlock", "Warrior"};
raceClasses = classes;
}
//Night elf
else if(r.toLowerCase().equals("night elf")) {
String[] classes = {"Druid", "Hunter", "Priest", "Rogue", "Warrior"};
raceClasses = classes;
}
//Default dwarf(dwarfs rule!)
else {
raceClasses = new String[1];
raceClasses[0] = "Error";
}
//Create the combo box
classComboBox = new JComboBox(raceClasses);
classComboBox.setBounds(new Rectangle(250, 30, 100, 20));
classComboBox.addActionListener(this);
this.getContentPane().add(classComboBox, null);
}
}
[edited by - Nanven on March 10, 2004 9:06:07 PM]