samedi 7 mars 2015

project skipping my if statement? Java

So starting out, i am new to java. Very new. I decided to make my own program tonight and 6hrs later I have almost got there. My program is to launch a combo box, depending on which thing you select and when you click the button it is supposed to set that to a string. It then compares the string in an if statement and writes to a file according to it being true or false. Expect for I cant seem to make it write as if the statement was true. Im having issues with the debugger and i need help xD. Here is my code



String[] realms = {"Choose a realm", "True-WoW", "Eternal-WoW"};
JComboBox RealmList = new JComboBox(realms);
JButton button = new JButton("Change Realmlist and Launch WoW");
JLabel label = new JLabel("Realms: ");
JLabel label2 = new JLabel();
JLabel label3 = new JLabel("Made by: Ian D");

String chosenRealm;

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
WoWRealmlist classInstance = new WoWRealmlist();
classInstance.comboBox();
classInstance.changeRealm();
//classInstance.runWoW();

} //End of main

public void comboBox() {

RealmList.setSelectedIndex(0);

JFrame f = new JFrame("WoW Realm Chooser");
f.setVisible(true);
f.setSize(300, 150);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel p = new JPanel();
p.add(label);
p.add(RealmList);
p.add(button);
p.add(label3);

f.add(p);

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chosenRealm = RealmList.getSelectedItem().toString();
label2.setText(chosenRealm);


} //End of actionPerformed

}); //End of button.addActionListener

} //End of comboBox

public void changeRealm() {

if ("True-WoW".equals(chosenRealm)) {

File f = new File("E:\\Prgram Files\\WoW Wrath of the Lich King\\Data\\enUS\\", "realmlist.wtf");
try {
FileWriter fw = new FileWriter(f, false);
fw.flush();
fw.write("set realmlist login.truewow.org");
fw.close();

} catch (Exception ex) {

} //End of catch

} //End of if
else {
File f = new File("E:\\Prgram Files\\WoW Wrath of the Lich King\\Data\\enUS\\", "realmlist.wtf");
try {
FileWriter fw = new FileWriter(f, false);
fw.flush();
fw.write("set realmlist logon.eternal-wow.com");
fw.close();

} catch (Exception ex) {

} //End of catch`


pardon me for being a hack haha. chosenRealm should equal "True-WoW" and make my if statement true.


Aucun commentaire:

Enregistrer un commentaire