Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Question about GUI: JTextField


    Fran
     Share

    Recommended Posts

    Hey guys! Hope you're all doing great. 

     

    Was just wondering, as I am getting used to working with GUIs & scripting for RuneScape, if anyone could help with the following thing:

     

    I want the JTextField String that I introduce when I start the GUI, to be the input String in my main class. Please see the following:

     

    I have my GUI class, added a JTextField, as shows the following:

    logsNameField = new JTextField();
    contentPane.add(logsNameField);
    
    
    logsNameField.addActionListener(new ActionListener () {
    @Override
    public void actionPerformed(ActionEvent arg0) {
    String logsName = logsNameField.getText(); 
    } 
    }

    And in my main class, I want the input logsName from the GUI class, to be the input as follows:

     

    getInventory().interactWithItem(input from logsName, "Use");

     

    I know a way to do this would be using Getters, but how would that work with a JTextField?

     

    If someone can be explicit, I will greatly appreciate :)

    Edited by Franjey
    Link to comment
    Share on other sites

    The way I see it, the best method is to process everything in your Start Button. There's no reason to add it into your TextField's listener unless you want the GUI to be open and editable at any time. :/

    Link to comment
    Share on other sites

    The way I see it, the best method is to process everything in your Start Button. There's no reason to add it into your TextField's listener unless you want the GUI to be open and editable at any time. :/

     

    This. 

     

    I'll also re-post what I said to you on Skype:

    You should be using private variables in your GUI class along with getters for them. You should be making a new instance of your GUI in your script, use that to get data, then assign them to variables in your main script class with the getters and dispose of the GUI instance. Then you should be using those variables from your main class for your script.

     

    Example: http://dreambot.org/forums/index.php?/topic/880-haku-s-aio-woodcutter-source/

    Link to comment
    Share on other sites

    I've always made a GUI class which contains the structure of my GUI. Inside of that class I have getters for the user input. Create an instance of the GUI class on startup to access it while the script is running

    Link to comment
    Share on other sites

    plz stop linking ur shit code kthx

     

    Tell me what's wrong and I will improve it. =)

    Edited by Vlad
    Link to comment
    Share on other sites

    The way I see it, the best method is to process everything in your Start Button. There's no reason to add it into your TextField's listener unless you want the GUI to be open and editable at any time. :/

     

     

    This. 

     

    I'll also re-post what I said to you on Skype:

    You should be using private variables in your GUI class along with getters for them. You should be making a new instance of your GUI in your script, use that to get data, then assign them to variables in your main script class with the getters and dispose of the GUI instance. Then you should be using those variables from your main class for your script.

     

    Example: http://dreambot.org/forums/index.php?/topic/880-haku-s-aio-woodcutter-source/

     

     

    I've always made a GUI class which contains the structure of my GUI. Inside of that class I have getters for the user input. Create an instance of the GUI class on startup to access it while the script is running

    Okay thanks guys :) I use to do the same thing, maybe anyone had a better way :P

    Link to comment
    Share on other sites

     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.