Jump to content

Athylus

Recommended Posts

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?

Link to comment
Share on other sites

.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 by Viston
Link to comment
Share on other sites

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.

  • Like 4
Link to comment
Share on other sites

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:

  1. 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.
  2. Find the library's source code and include that into your script.
  3. 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 by liverare
  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...