Deceiver Posted August 19, 2015 Posted August 19, 2015 wat do Issue: I have this sick GUI for a script right? How do I get it to start/load a class from a different package? Select option from a JComboBox Hit "start" Start selected item with a matching class name? I've tried populating the JComboBox values two different ways, but neither prevailed, when trying to start the other class. My onLoop method: (I want to assume that the problem is in this hopefully) @Override public int onLoop() throws InterruptedException { try { Class.forName(getName(), true, null); // Class.forName((String) questName); log("trying to start: " + questName); } catch (Exception e) { log("failed to start: " + questName); e.printStackTrace(); } return 500; }
Extreme Scripts Posted August 19, 2015 Posted August 19, 2015 MyObject object = new MyObject(); public int onLoop(){ String shit = object.getCombobox().getSelectedItem().toString(); } Advice, learn basic java. 3
Apaec Posted August 19, 2015 Posted August 19, 2015 a straight forward way to do it is to have your class called 'Gui' which contains the code for your gui. in that class, you have an actionlistener for your start button which gets the current selected settings and sends them statically to your main class. here's how the actionlistener goes: btnStart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //code here eg: Main.food = (String) foodComboBox.getSelectedItem(); setVisible(false); } }); and your main class: //vars: public static String food; Gui GUI; @Override public void onStart() { GUI = new Gui(); GUI.setVisible(true); log("======================================================================"); log("script started or whatever"); } @Override public int onLoop() { while(GUI.isVisible()) sleep(400); return 200; } then the gui will feed you the values chosen on the gui when the start button is pressed, at the same time as running the script (breaking the while loop) and closing the gui. apa ps sorry for any typos, wrote most of the code in the reply box so there may be a few errors 1
Deceiver Posted August 19, 2015 Author Posted August 19, 2015 a straight forward way to do it is to have your class called 'Gui' which contains the code for your gui. in that class, you have an actionlistener for your start button which gets the current selected settings and sends them statically to your main class. here's how the actionlistener goes: btnStart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //code here eg: Main.food = (String) foodComboBox.getSelectedItem(); setVisible(false); } }); and your main class: //vars: public static String food; Gui GUI; @Override public void onStart() { GUI = new Gui(); GUI.setVisible(true); log("======================================================================"); log("script started or whatever"); } @Override public int onLoop() { while(GUI.isVisible()) sleep(400); return 200; } then the gui will feed you the values chosen on the gui when the start button is pressed, at the same time as running the script (breaking the while loop) and closing the gui. apa ps sorry for any typos, wrote most of the code in the reply box so there may be a few errors I have my GUI in my 'main' file. And, I have already added a ActionListenser: JButton button = new JButton("Start"); button.addActionListener(event -> { questName = (String) questBox.getSelectedItem().toString(); log("Selected Quest: " + questName); frame.dispose(); synchronized(Test.class) { Test.class.notify(); } }); So, it successfully logs "Selected Quest", and disposes. 1