Results 1 to 2 of 2
  1. #1
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Default boolean condition creating problem

    Hi,
    Hope you all will be fine. Actually of course this is a continuation.Anyways. I have a form with two buttons on it. Like this

    Java Code:
            sms = new Button("SMS");
            sms.addActionListener(this);
           //sms.addFocusListener(this);
    
    
            internet = new Button("Internet");
            internet.addActionListener(this);
    
             form1.addComponent(sms);
            form1.addComponent(internet);
    
             public void actionPerformed(ActionEvent evt) {
    		//check which command cliked
    		if (evt.getCommand()==cmdExit) {
    			notifyDestroyed();
                    
    		} else if (((evt.getCommand()==cmdSelect) && (sms.hasFocus())) ) {
    			form2.show();
    		} else if (evt.getCommand()==cmdBack) {
    			form1.show();
    		} else if (evt.getCommand()==cmdSend) {
                        String text = txtArea1.getText();
                        System.out.println("txtArea1 contain this text: " + text);
    The condition is working

    Java Code:
    } else if (((evt.getCommand()==cmdSelect) && (sms.hasFocus())) ) {
    			form2.show();
    But as you know mobile phone also has a center button surrounded between four directional keys. i want that it also work Means if user select sms button and press the middle button then form2 will be shown. I read it for use third soft button you use fireClicked(). But actually i don't know how to use it.I tried it like this

    Java Code:
        protected void fireClicked(){
          System.out.println("I am in fireclicked");
          if (sms.isEnabled()){
              form2.show();
          }
        }
    
        protected boolean isSelectableInteraction(){
            return true;
        }
    But it isn't working

    But when i change the condition like this

    Java Code:
     else if ( (sms.isEnabled()) || (((evt.getCommand()==cmdSelect) && (sms.hasFocus()))) ) {
    It worked but what is happening the condition

    Java Code:
    } else if (evt.getCommand()==cmdBack) {
    			form1.show();
    is not working in this case. It worked when sms.isEnabled is not present but isn't working in this case. Nothing happen when i press back command which is on second form. In first case it works. Any idea why it is happening.

    Thanks

  2. #2
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Smile

    Hi,
    when i change the conditon like this it works. But i want to know what was wrong with the previous case.Please tell me

    Java Code:
     public void actionPerformed(ActionEvent evt) {
    
            if ((sms.isEnabled()) && (sms.hasFocus()) ){
                form2.show();
            }
    		//check which command cliked
    		if (evt.getCommand()==cmdExit) {
    			notifyDestroyed();
                    //} else if (evt.getCommand()==cmdSelect) {
                   //} else if ( (sms.isEnabled()) || (((evt.getCommand()==cmdSelect) && (sms.hasFocus()))) ) {
    	       } else if ((((evt.getCommand()==cmdSelect) && (sms.hasFocus()))) ) {
    			form2.show();
    
    
    		} else if (evt.getCommand()==cmdBack) {
    			form1.show();
    		} else if (evt.getCommand()==cmdSend) {
                        String text = txtArea1.getText();
                        System.out.println("txtArea1 contain this text: " + te
    Thanks

Similar Threads

  1. IF-Condition in a String
    By lenaz in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 12:07 PM
  2. [SOLVED] boolean method problem
    By shadowblade19 in forum New To Java
    Replies: 6
    Last Post: 11-30-2008, 02:01 AM
  3. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  4. JFrame (closing under a condition)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:17 AM
  5. problem with using string in if condition
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 10:40 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
  •