Spout Text Fields, and Buttons.

Discussion in 'Plugin Development' started by MuisYa, Sep 9, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    MuisYa

    Soo, im making a plugin. Got already a few buttons working well etc etc.
    But i cant find out one thing:
    When i press a button, i want to receive the text out of a TextField, can someone help a bit with that? Thanks alot!
     
  2. Offline

    Samkio

  3. Offline

    MuisYa

    @Samkio Haha, cool that you give a reaction :3 Famous guy xD
    I know that, but the problem is... It doesn really work for me...
    Or i dont know how to handle it.

    Muis

    @Samkio
    Code:
    if (event.getButton().getText().equals("Set time")) {
        // what here? Fieldname: timeField
    }
    
    It should get the text, and than i will use that to set the time, so it will be a int.
    Ill use a Integer parser later..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  4. Offline

    Samkio

    Ah i see.
    Well i assume you have a screen listener?

    Off the top of my head: (Sorry if there are mistakes xD)

    for(Widget w:event.getScreen().getAttachedWidgets()){
    if(w.getID()==//uuid of TextField){
    w.getText();
    }
    //Will need some casting.
    }

    Hope this helps. You will need to save UUID of the textfield.
     
  5. Offline

    MuisYa

    @Samkio I will try it later, thanks alot!

    @Samkio Soooo i dont really get it...

    This is the last part of the screenlistener called: ButtonListener
    Code:
            if (event.getButton().getText().equals("X")) {
                event.getPlayer().getMainScreen().closePopup();
            }
            for(Widget w:event.getScreen().getAttachedWidgets()){
                UUID timeField;
                if(w.getId() == timeField){
                ((TextField) w).getText();
                }
                event.getPlayer().sendMessage("This works?!");
                }
    
            }
    Eeehm, i just dont get where to paste it or something... Because this won't work. It doent get activated...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  6. Offline

    Daniel Heppner

    Lol Samkio. Use code tags. :p
     
  7. Offline

    MuisYa

  8. Offline

    Daniel Heppner

    If he posts as much as he does on here, he should be able to use code tags. I would've thought that Sammy would be bugging him about being lazy.
     
    Samkio likes this.
  9. Offline

    Samkio

    Code tags are effort... xD
    Why not go the whole way and use Java syntax.

    Code:java
    1.  
    2. if (event.getButton().getText().equals("X")) {
    3. String time = "";
    4. UUID timeField;
    5. for(Widget w:event.getScreen().getAttachedWidgets()){
    6. if(w.getId() == timeField){
    7. time = ((TextField) w).getText();
    8. break;
    9. } }
    10.  
    11. if(!time.equalsIgnoreCase("")){
    12. //Do stuff.
    13. } }
    14.  


    Btw thats how it should be. I don't recommend closing the popup and then searching for widgets... as well. The widgets will be removed aswell. xD
    Do it after.
     
  10. Offline

    Daniel Heppner

    I love being lazy. XD
     
  11. Offline

    MuisYa

    @Samkio @Daniel Heppner if there is someone lazy today, its me -____-
    Soo tired.. Thanks for the code Samkio, ill test it in a minute.

    Code:
            if (event.getButton().getText().equals("Set time")) {
                String time = "";
                UUID timeField;
                for(Widget w:event.getScreen().getAttachedWidgets()){
                    if(w.getId() == timeField){
                        time = ((TextField) w).getText();
                                    break;
                                    }
                }
    
                 if(!time.equalsIgnoreCase("")){
                     int timeAmount = Integer.parseInt(timeField.getText());
                     event.getPlayer().getWorld().setTime(timeAmount);
                  }
            }
    1 problem left: "int timeAmount = Integer.parseInt(timeField.getText());"
    The method getText() is undefined for the type UUID.

    The rest works i hope! Eclipse doesnt give errors anyway ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  12. Offline

    sddddgjd

    Well,timeField is just an UUID,it's not the actual button! Not sure what you want to acomplish,but it's probably event.getButton.getText(),again!
     
  13. He is correct ^_^
     
  14. Offline

    Samkio


    Code:
    int timeAmount = Integer.parseInt(time);
     
  15. Offline

    MuisYa

    @sddddgjd I dont want the text out of a button. I want the text from a field, when i hit a button.
    And in the field, there will be a timeAmount which changes the current time (When button pressed)

    Clear like that?
    MuisYa

    @tips48 @sddddgjd Well, he is probably right, but that doesnt fix my problem...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  16. Offline

    MuisYa

    @Samkio Nice! Error at that line is now fixed. 1 problem left -____-
    Code:
    if(w.getId() == timeField){
    The "timeField" gives a error now...

    Thanks! That helps :D

    @tips48 Look at the first post?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  17. Offline

    sddddgjd

    int timeAmount = Integer.parseInt(time);
    Will work!
     
  18. Offline

    Samkio

    @MuisYa
    Yeah when you create the textfield store it somewhere/somehow and then load it back up later.
    Possibly a Map perhaps?

    It's not initialised your just stating it's there. xD
     
  19. Offline

    MuisYa

    Current code, if anyone wants to see:
    Code:
            if (event.getButton().getText().equals("Set time")) {
                String time = "";
                UUID timeField;
                for(Widget w:event.getScreen().getAttachedWidgets()){
                    if(w.getId() == timeField){
                        time = ((TextField) w).getText();
                                    break;
                                    }
                }
    
                 if(!time.equalsIgnoreCase("")){
                     int timeAmount = Integer.parseInt(time);
                     event.getPlayer().getWorld().setTime(timeAmount);
                  }
            }  
    @Samkio Are you sure it cant be done easier? I mean...
    Normal Java just has:
    And i never worked with Maps before... -_____-

    @sddddgjd I know, it did. Thanks but i got another problem right now..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  20. Offline

    sddddgjd

    You create a new UUID called timeField,but you don't give it any value...
     
  21. Offline

    MuisYa

    @sddddgjd Soo, i remove it or do what?
    Sorry, in a noooob D:
     
  22. Offline

    sddddgjd

    No,you give it a value from somewhere...
     
  23. Offline

    MuisYa

    @sddddgjd A BullShit value or the Time value gotten out the TextField.

    @sddddgjd Oke, i did this:
    Code:
            if (event.getButton().getText().equals("Set time")) {
                String time = "";
    
                UUID timeField = null;
                for(Widget w:event.getScreen().getAttachedWidgets()){
                    if(w.getId() == timeField){
                        time = ((TextField) w).getText();
                                    break;
                                    }
                }
    
                 if(!time.equalsIgnoreCase("")){
                     int timeAmount = Integer.parseInt(time);
                     event.getPlayer().getWorld().setTime(timeAmount);
                  }
            } 
    But that doesnt work... The button doesnt do anything..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  24. Offline

    sddddgjd

    No,not a bullshit value...the RIGHT value!
    Ok,what's supposed to be in timeField? What does it define?
     
  25. Offline

    MuisYa

    I got this GUI where you can change times.
    So you can fill in a time value in the field. Hit the button. And the time is changed.
    field: timeField
    button text: Set time

    @sddddgjd

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
Thread Status:
Not open for further replies.

Share This Page