Login Buttons and Action Listeners, can you help me please?

13 views
Skip to first unread message

TheHyng

unread,
Mar 24, 2017, 7:56:50 AM3/24/17
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS
Simulator
Device

Hello, I've created a button called "login" and added an actionlistener for when its clicked, but above that I have 2 textfields, the password and the username, how do I add the text input from username and password to the actual variables and verify it?

String user1 = null, pass1 = null;
Form login = new Form("Login");
        setBackCommand
(login);
       
TextField username = new TextField("","Username", 20, TextField.INITIAL_CAPS_WORD);
       
TextField password = new TextField("", "Password", 20, TextField.PASSWORD);
       
Button userlogin = new Button("Login");
        userlogin
.addActionListener(new ActionListener(){
           
@Override
           
public void actionPerformed(ActionEvent evt){
               
if (user1==null && pass1==null)
                   
Dialog.show("Warning!", "Please, fill all the ", "Ok","Cancel");
               
else
                   
//How do I add the textfield content to the variables user1 and pass1?
                   
Dialog.show("Logged in!", "Log in successful! ", "Ok", "Close Dialog");
           
}
       
});
        login
.addComponent(username);
        login
.addComponent(password);
        login
.addComponent(userlogin);

There is no actual Login system going on, on background

howud...@gmail.com

unread,
Mar 24, 2017, 1:48:32 PM3/24/17
to CodenameOne Discussions
look at TextField#getText / setText  ie: user1 = username.getText()

TheHyng

unread,
Mar 24, 2017, 6:16:25 PM3/24/17
to CodenameOne Discussions
omg ty so much!
Reply all
Reply to author
Forward
0 new messages