Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Attempting to convert from An Option Box to A Text Field...Issues Though

Featured Replies

Ok, so here is my current GUI code for my Curse Bot

	    private void createGUI(){
	        final int GUI_WIDTH = 350, GUI_HEIGHT = 85;
	        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	        final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);
	        final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
	        gui = new JFrame("XCurseCustom V(0.3)");
	        gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT);
	        gui.setResizable(false);
	        JPanel panel = new JPanel();
	        gui.add(panel);
	        JLabel label = new JLabel("Select A Spell and A Monster!"); // Create a label
	        label.setForeground(Color.WHITE); // Set text color to white
	        panel.add(label); // Add it to the JPanel
	        JTextField selectYourMonster = new JTextField(20);
	        selectYourMonster.addActionListener(e -> monsterSelect = selectYourMonster.getText().toString());
	       	panel.add(selectYourMonster);
	        JButton startButton = new JButton("Start");
	        startButton.addActionListener(e -> {
	            started  = true;
	            gui.setVisible(false);
	        });
	        panel.add(startButton);
	        gui.setVisible(true);
	    }

I have also declared

	private String monsterSelect = "";

and have the action code set to 

NPC NPC = npcs.closest(monsterSelect);

Yet when I go to start the bot it acts like there was no input in the box (even if I put something in there).

Now if I change the declaration to say "Monk of Zamorak" It will then go after the Monk of Zamorak. 

 

So what I'm noticing is that somewhere my code is messed up and it's not storing the data from the GUI.

I've looked a lot online and on these forums and can't really find a proper answer.

 

 

edit: Also, to those who are taking the time to answer, PLEASE explain the process and why my method was incorrect and why yours is correct. I'm really really interesting in learning this and would love to get in-depth analysis on what is wrong.

Edited by creationx

You could try this:

startButton.addActionListener(e -> {
	            started  = true;
                    monsterSelect = selectYourMonster.getText().toString();
	            gui.setVisible(false);
	        }); 

And if you are doing this to stop your script:

public void onStart(){
    gui.setVisible(true);

    while(started != true){
       Thread.sleep();
    }
}

Don't do it, do it like I show in this tutorial: http://osbot.org/forum/topic/91963-using-synchronized-to-your-advantage/

Ok, so here is my current GUI code for my Curse Bot

	    private void createGUI(){
	        final int GUI_WIDTH = 350, GUI_HEIGHT = 85;
	        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	        final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);
	        final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
	        gui = new JFrame("XCurseCustom V(0.3)");
	        gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT);
	        gui.setResizable(false);
	        JPanel panel = new JPanel();
	        gui.add(panel);
	        JLabel label = new JLabel("Select A Spell and A Monster!"); // Create a label
	        label.setForeground(Color.WHITE); // Set text color to white
	        panel.add(label); // Add it to the JPanel
	        JTextField selectYourMonster = new JTextField(20);
	        selectYourMonster.addActionListener(e -> monsterSelect = selectYourMonster.getText().toString());
	       	panel.add(selectYourMonster);
	        JButton startButton = new JButton("Start");
	        startButton.addActionListener(e -> {
	            started  = true;
	            gui.setVisible(false);
	        });
	        panel.add(startButton);
	        gui.setVisible(true);
	    }

I have also declared

	private String monsterSelect = "";

and have the action code set to 

NPC NPC = npcs.closest(monsterSelect);

Yet when I go to start the bot it acts like there was no input in the box (even if I put something in there).

Now if I change the declaration to say "Monk of Zamorak" It will then go after the Monk of Zamorak. 

 

So what I'm noticing is that somewhere my code is messed up and it's not storing the data from the GUI.

I've looked a lot online and on these forums and can't really find a proper answer.

 

 

edit: Also, to those who are taking the time to answer, PLEASE explain the process and why my method was incorrect and why yours is correct. I'm really really interesting in learning this and would love to get in-depth analysis on what is wrong.

 

Action listeners on text fields only trigger when you hit ENTER.

Some approaches you can use are either to make the textfield a class member, and use its value directly in the closest filter; or use an event on the button instead.

Though in reality you should probably redesign the whole thing, and separate the user interface code from the main script class.

  • Author

Thank you for your advice everyone! I still have tons to learn, but I appreciate the help.

Thank you for your advice everyone! I still have tons to learn, but I appreciate the help.

 

Also, alternatively to getting the screen size, setting null as the relative location will put the frame in the center of the screen.

frame.setLocationRelativeTo(null)

Action listeners on text fields only trigger when you hit ENTER.

Some approaches you can use are either to make the textfield a class member, and use its value directly in the closest filter; or use an event on the button instead.

Though in reality you should probably redesign the whole thing, and separate the user interface code from the main script class.

 

Or you could just add a document listener instead of an action listener?

 

https://docs.oracle.com/javase/tutorial/uiswing/events/documentlistener.html

 

edit: think this works

selectYourMonster.getDocument().addDocumentListener(new DocumentListener() {
    @Override
    public void insertUpdate(DocumentEvent e) {
        onUpdate();
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        onUpdate();
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        onUpdate();
    }

    private void onUpdate(){
        monsterSelect = selectYourMonster.getText();
    }
});

Edited by Chicken Wing

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.