June 10, 201510 yr I am familiar with java, but I am brand new to scripting and the OSBot API. I looked in the API for some GUI, I could not find anything. So I tried to open up a JFrame using Java Swing on the script start method.. I am looking to just put some checkboxes and some dropdowns for my woodcutting script for Ex: Pick from yews or willows. Thanks!
June 10, 201510 yr Create new class for the GUI (I prefer Eclipse Windowbuilder) and create new JFrame. Then in your onStart() method set the gui visible and while it is visible read the data. And ofcourse a button to hide the gui and start the script.
June 10, 201510 yr Here I made it quickly for you public class GUI extends JFrame { private JPanel contentPane; public JButton btnNewButton; public JComboBox<String> comboBox; public GUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 148, 108); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); btnNewButton = new JButton("New button"); btnNewButton.addActionListener(ae -> setVisible(false)); btnNewButton.setBounds(20, 42, 89, 23); contentPane.add(btnNewButton); comboBox = new JComboBox<String>(); comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"Willow", "Yew"})); comboBox.setBounds(10, 11, 121, 20); contentPane.add(comboBox); } } Also in your onStart private int tree; //0 -> willow, 1 -> yew public void onStart() { GUI g = new GUI(); g.setVisible(true); while(g.isVisible()) {} tree = g.comboBox.getSelectedIndex(); } And btw API has nothing to do with gui
June 10, 201510 yr Here I made it quickly for you public class GUI extends JFrame { private JPanel contentPane; public JButton btnNewButton; public JComboBox<String> comboBox; public GUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 148, 108); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); btnNewButton = new JButton("New button"); btnNewButton.addActionListener(ae -> setVisible(false)); btnNewButton.setBounds(20, 42, 89, 23); contentPane.add(btnNewButton); comboBox = new JComboBox<String>(); comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"Willow", "Yew"})); comboBox.setBounds(10, 11, 121, 20); contentPane.add(comboBox); } } Also in your onStart private int tree; //0 -> willow, 1 -> yew public void onStart() { GUI g = new GUI(); g.setVisible(true); while(g.isVisible()) {} tree = g.comboBox.getSelectedIndex(); } And btw API has nothing to do with gui Don't forget to post your Swing related code to the Event Dispatch Thread! Ensures no inconcistencies with any GUI code that may be executing. As for the busy-waiting, wait/notify (guarded blocks) would be the best solution for what you want to achieve. It ensures a thread isn't continuously running while not executing any code (consuming CPU power). If you choose to busy-wait (maybe you find wait/notify too complex, which if so, message me), you should at least sleep for 1 or 2 millisec between each iteration, to ensure CPU usage isn't at max (You'd be surprised how much 2 ms helps). Hope you found this info beneficial! And thanks for the contribution! Edited June 10, 201510 yr by fixthissite
June 10, 201510 yr Create new class for the GUI (I prefer Eclipse Windowbuilder) and create new JFrame. Then in your onStart() method set the gui visible and while it is visible read the data. And ofcourse a button to hide the gui and start the script. Look up a tutorial for eclipse window builder. pfft Netbeans UI builder > Eclipse UI builder
Create an account or sign in to comment