RetroBot 35 Posted June 24, 2017 The GUI works fine when I first run the script, but when I stop the script and start it back up again the GUI pops up for a second then closes immediately. How can I solve this problem? Any help is much appreciated. @Override public void onStart() { startTime = System.currentTimeMillis(); GUI GUI = new GUI(); Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int screenW = (screensize.width) / 2; int screenH = (screensize.height) / 2; GUI.setVisible(true); GUI.setLocation((screenW / 2), (screenH / 2)); while (!GUI_COMPLETE) { sleep(500); } GUI.setVisible(false); log("Script has started!"); }
Polymorphism 48 Posted June 24, 2017 Try doing something about that while loop. On exit set gui_complete true or break the loop is gui is not visible
RetroBot 35 Author Posted June 24, 2017 Try doing something about that while loop. On exit set gui_complete true or break the loop is gui is not visible I set gui_complete to true when I press the start button (forgot to post that part) private void startButtonActionPerformed(java.awt.event.ActionEvent evt) throws IOException { Main.GUI_COMPLETE = true; playerSettings = playerCheck.isSelected(); npcSettings = npcCheck.isSelected(); lootSettings = lootCheck.isSelected(); destinationCombobox = destinationCombo.getSelectedItem().toString(); }
Polymorphism 48 Posted June 24, 2017 I set gui_complete to true when I press the start button (forgot to post that part) private void startButtonActionPerformed(java.awt.event.ActionEvent evt) throws IOException { Main.GUI_COMPLETE = true; playerSettings = playerCheck.isSelected(); npcSettings = npcCheck.isSelected(); lootSettings = lootCheck.isSelected(); destinationCombobox = destinationCombo.getSelectedItem().toString(); } Based off this code, can't tell. But if you're trying to set the gui in the middle of the screen do this gui.setLocationRelativeTo(null); Also -Make your GUI a field, not a local variable in the onStart -Dont make the GUI variable name the exact same as its type --GUI GUI = new GUI() <--bad --Gui gui = new GUI() <--good
Dinh 496 Posted June 24, 2017 The GUI works fine when I first run the script, but when I stop the script and start it back up again the GUI pops up for a second then closes immediately. How can I solve this problem? Any help is much appreciated. @Override public void onStart() { startTime = System.currentTimeMillis(); GUI GUI = new GUI(); Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int screenW = (screensize.width) / 2; int screenH = (screensize.height) / 2; GUI.setVisible(true); GUI.setLocation((screenW / 2), (screenH / 2)); while (!GUI_COMPLETE) { sleep(500); } GUI.setVisible(false); log("Script has started!"); } Instead of Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int screenW = (screensize.width) / 2; int screenH = (screensize.height) / 2; GUI.setVisible(true); GUI.setLocation((screenW / 2), (screenH / 2)); just do GUI.setLocationRelativeTo(null);
Recommended Posts
Archived
This topic is now archived and is closed to further replies.