Athylus Posted February 5, 2018 Share Posted February 5, 2018 There is a problem with my GUI. I am trying to use SWT for this. I made a separate class next to my main one called GUI, in it I have a SWT GUI which has a combo box and a start script button. import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.graphics.Point; public class GUI { public String treeName; public static String errorMessage; protected Shell shell; /** * Launch the application. * @param args */ public static void main(String[] args) { try { GUI window = new GUI(); window.open(); } catch (Exception e) { errorMessage = "Error"; } } /** * Open the window. */ public void open() { Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } /** * Create contents of the window. */ protected void createContents() { shell = new Shell(); shell.setMinimumSize(new Point(136, 40)); shell.setSize(272, 240); shell.setText("SWT Application"); shell.setLayout(null); Combo combo = new Combo(shell, SWT.READ_ONLY); combo.setBounds(66, 44, 128, 23); combo.setItems(new String[] {"Tree", "Oak", "Willow", "Maple", "Yew", "Magic"}); combo.select(0); Button btnNewButton = new Button(shell, SWT.NONE); btnNewButton.setBounds(66, 108, 128, 54); btnNewButton.setText("Start script"); btnNewButton.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { treeName = combo.getText(); shell.close(); } }); } } In my main: public void onStart() { GUI gui = new GUI(); } It's not even showing up! The logger is giving me some error messages. Uncaught exception! java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite at Main.onStart(Main.java:26) at org.osbot.rs07.event.ScriptExecutor.IiIiiiiiIiIi(yl:197) at org.osbot.rs07.event.ScriptExecutor.start(yl:28) at org.osbot.Lb.run(vf:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 7 more [INFO][Bot #1][02/05 05:34:10 PM]: Terminating script Skeleton... [INFO][Bot #1][02/05 05:34:10 PM]: Script Skeleton has exited! Is it possible to make SWT work with OSBot? Quote Link to comment Share on other sites More sharing options...
Viston Posted February 5, 2018 Share Posted February 5, 2018 (edited) .setVisible(); @Athylus on your onStart() On your onStart do: GUI.setVisible(); while (!GUI_COMPLETE) { sleep(300); } GUI.setVisible(false); On the gui button, once it's clicked, change the gui complete boolean to true, and it'll break out of the loop, then hide the gui. Edited February 5, 2018 by Viston Quote Link to comment Share on other sites More sharing options...
Butters Posted February 5, 2018 Share Posted February 5, 2018 SWT is some sort of fancy library? OSBot doesn't allow external dependencies in scripts. You can copy paste the source code of your dependency into the script though. Though would recommend just using normal swing. Quote Link to comment Share on other sites More sharing options...
Vilius Posted February 5, 2018 Share Posted February 5, 2018 1 hour ago, Viston said: .setVisible(); @Athylus on your onStart() On your onStart do: GUI.setVisible(); while (!GUI_COMPLETE) { sleep(300); } GUI.setVisible(false); On the gui button, once it's clicked, change the gui complete boolean to true, and it'll break out of the loop, then hide the gui. No, just no. 1 hour ago, nosepicker said: SWT is some sort of fancy library? OSBot doesn't allow external dependencies in scripts. You can copy paste the source code of your dependency into the script though. Though would recommend just using normal swing. SWT is an external library/toolkit developed by IMB, it builds upon AWT. And Swing is built on AWT. So @OP use swing and when displaying it pass it to the EDT because its not thread safe. 4 Quote Link to comment Share on other sites More sharing options...
liverare Posted February 5, 2018 Share Posted February 5, 2018 (edited) import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.graphics.Point; Your problem is that OSBot doesn't come packaged with the SWT ("org.eclipse.swt") library. Your solutions are either: Ask a @Zach or @Alek to see if they can add the library into OSBot. This is unlikely due to it being more overhead for something that's likely to be very niche. Find the library's source code and include that into your script. Use the Swing ("javax.swing") library, because that is packaged with Java by default. You can look into JOptionPane to achieve what it is you're after, but in quite literally one line of code. I'd chose no.3 just because it's the easiest and doesn't add any additional overhead. You can literally just do: String[] trees = { "normal", "oak", "willow" }; Object input = JOptionPane.showInputDialog(bot.getCanvas(), "Select a tree", "Woodcutter", JOptionPane.QUESTION_MESSAGE, null, trees, trees[0]); String tree = null; if (input != null) { tree = input.toString(); } Edited February 5, 2018 by liverare 4 Quote Link to comment Share on other sites More sharing options...
Athylus Posted February 16, 2018 Author Share Posted February 16, 2018 Thanks for the replies, I'm sure I can figure it out from here on. I guessed that SWT was not compatible as it was not even executing in any form whatsoever. I will use swing. Quote Link to comment Share on other sites More sharing options...