Results 1 to 6 of 6
  1. #1
    mfayaz is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default Login form issue

    ok, i'm complete noob and trying to understand why the following login form doesn't show an error msg box when the fields are empty.
    IDE eclipse 3

    Java Code:
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.SWT;
    //import org.eclipse.swt.events.*;
    
    
    public class loginform
    {
    
    		Display display = new Display();
    		Shell shell = new Shell(display);
    		 Label label1,label2;
    		  Text username;
    		  Text password;
    		  //Text text;
    		  
    		public loginform()
    		{
    			shell.setLayout(new GridLayout(2, false));
    			shell.setText("long form1");
    			label1 = new Label(shell, SWT.NULL);
    			label1.setText("User Name:");
    		
    			username = new Text(shell, SWT.BORDER);
    			username.setText("");
    			username.setTextLimit(20);
    			
    			//password
    			label2 = new Label(shell, SWT.NULL);
    			label2.setText("Password:");
    
    			password = new Text(shell, SWT.BORDER);
    			password.setText("");
    			password.setEchoChar('+');
    			password.setToolTipText("pass goes here");
    			
    			Button button = new Button(shell,SWT.PUSH);
    			button.setText("Send now");
    			
    			button.addListener(SWT.Selection, new Listener()
    			{
    				public void handleEvent(Event event)
    				{
    					String gotusername = username.getText();
    					String gotpassword = password.getText();
    					
    					if(gotusername == "")
    					{
    						MessageBox msg = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
    						msg.setMessage("Please enter user name");
    						msg.open();
    					}
    					
    					if(gotpassword == "")
    					{
    						MessageBox msg = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
    						msg.setMessage("Please enter password");
    						msg.open();
    					}
    					else
    					{
    						MessageBox msg = new MessageBox(shell, SWT.NULL);
    						msg.setText("Wlcom Window");
    						msg.setMessage("Welcome" + username.getText());
    						msg.open();
    					}
    				}
    			}
    			);
    			
    			shell.pack();
    			shell.open();
    			while(!shell.isDisposed())
    			{
    				if(!display.readAndDispatch())
    				{
    					display.sleep();
    				}
    			}
    			display.dispose();
    		}
    		
    		public static void main(String[] args)
    		{
    			new loginform();
    		}		
    }
    Last edited by mfayaz; 03-27-2009 at 03:04 PM.

  2. #2
    mfayaz is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    anybody? :(

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    10

    Default

    need to be more specific with what the issue is, but you can't compare strings with "==". check out the equals and compareTo methods in the String doc

  4. #4
    mfayaz is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    to be more specific, i need the following lines of codes to be active, however i'm not getting any message box although the fields are empty.

    Java Code:
    if(gotusername == "")
    {
    MessageBox msg = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
    msg.setMessage("Please enter user name");
    msg.open();
    }
    					
    if(gotpassword == "")
    {
    MessageBox msg = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING | SWT.CANCEL);
    msg.setMessage("Please enter password");
    msg.open();
    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    29

    Default

    And you're still comparing Strings using "==" despite what emceenugget told you (and all of us will second). Why?

    to emcee's methods, I'll also add the String method isEmpty().

  6. #6
    mfayaz is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

Similar Threads

  1. SWT login form
    By Sureshgurram in forum SWT / JFace
    Replies: 4
    Last Post: 09-07-2009, 04:14 PM
  2. Replies: 6
    Last Post: 11-28-2008, 07:55 AM
  3. help needed regarding LOGIN form
    By innocent.crook in forum New To Java
    Replies: 2
    Last Post: 07-08-2008, 05:03 PM
  4. Replies: 0
    Last Post: 06-25-2008, 01:41 PM
  5. can i make a login form?
    By mitsakos in forum New To Java
    Replies: 2
    Last Post: 12-19-2007, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •