Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 53
Like Tree2Likes

Thread: Problem with action performing !!

  1. #21
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    CMD result:
    --------------------

    D:\tutor>java IdealWeight
    height h=sl*sl = 2500
    Male Weight h/28 = 89
    Female W h/30 = 83

    D:\tutor>
    (this time slider at 50 inches of height)

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    Where do you print out the value of the slider as it changes?
    Then after its value changes, where do you print out the new values that are computed using that new slider value?

    Also what are the values of h, h2 and h3 as the code executes?

    You need LOTS of println statements to show ALL of the variables as their values change.

  3. #23
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    D:\tutor>java IdealWeight
    height h=sl*sl = 2500
    Male Weight h/28 = 89
    Female W h/30 = 83

    D:\tutor>

    This time Slider at 50 inches of height

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    Did you read my last post?

    What you posted looks like what you posted before.


    Where do you print out the value of the slider as it changes?
    Then after its value changes, where do you print out the new values that are computed using that new slider value?

    Also what are the values of h, h2 and h3 as the code executes?

    You need LOTS of println statements to show ALL of the variables as their values change.

  5. #25
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    i store JButton value in a string !
    public void actionPerformed(ActionEvent ae) {

    if("Female".equals(ae.getActionCommand())) {
    if(f.isSelected() );
    jb2 = f.getText();

    and then ask to slider for execution

    public void stateChanged( ChangeEvent evt )
    {

    JSlider source = (JSlider)evt.getSource();

    if ( !source.getValueIsAdjusting( )) {
    sl = source.getValue();
    h = sl*sl;
    h2 = h/28;
    h3 = h/30;

    if(evt.getSource()!=jb2);
    ans = h2 +"";
    textA.setText(ans);

    }else{

    ans2 = h3 +"";
    textA.setText(ans2);


    }
    }

    slider works fine but ' ELSE ' doesn't working.
    slider show value of male
    why Else is not in work. any suggestion please.

  6. #26
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Problem with action performing !!

    Java Code:
    if(evt.getSource()!=jb2);
    Hmmmm!

  7. #27
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    Java Code:

    if(evt.getSource()!=jb2);

    Hmmmm!
    LOL

    I change the code

    if(evt.getSource() ==jb2);
    ans2 = h3 +"";
    textA.setText(ans2);

    }else{

    ans = h2 +"";
    textA.setText(ans);

    and now just female's formula is in work 'ELSE' ... not working

  8. #28
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Problem with action performing !!

    You didn't make the correct change. Take a hard look at the end of your if statement.

  9. #29
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    What's wrong with the compilers. I get an warning message when I compile with an empty statement
    Java Code:
    Running: F:\Java\jdk1.6.0_29\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;.;..\. TestCode7.java
    
    TestCode7.java:200: warning: [empty] empty statement after if
          if('a' > 'b');
                       ^
    1 warning

  10. #30
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Problem with action performing !!

    I guess it depends upon the compiler. Since it is legal to write an if statement like that it is not an error and only a warning. But other compilers won't even give the warning.

  11. #31
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    public void stateChanged( ChangeEvent evt )
    {

    JSlider source = (JSlider)evt.getSource();

    if ( !source.getValueIsAdjusting( )) {
    sl = source.getValue();
    h = sl*sl;
    h2 = h/28;
    h3 = h/30;

    if(evt.getSource() ==jb2);
    ans2 = h3 +"";
    textA.setText(ans2);

    }else{

    ans = h2 +"";
    textA.setText(ans);


    }
    }
    Else is dead .

  12. #32
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Problem with action performing !!

    Oh my fargin gawd!

    Remove the semi colon from the end of the if statement!
    and replace it with a {

  13. #33
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    @baig-sh
    If you'd properly line up the statement with the ending } with the statement with the openning { you will see that you do not have enough { for the code to be nested as you have intended it to be.
    Java Code:
    public void stateChanged( ChangeEvent evt )
    {
     
       JSlider source = (JSlider)evt.getSource();
            
        if ( !source.getValueIsAdjusting( )) {
            sl = source.getValue();
            h = sl*sl;
            h2 = h/28;
            h3 = h/30;
    
            if(evt.getSource() ==jb2);
                ans2 = h3 +"";
                textA.setText(ans2);
     
        }else{
     
    	   ans = h2 +"";
    	   textA.setText(ans);
        } 
     }

  14. #34
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    public void stateChanged( ChangeEvent evt )
    {

    JSlider source = (JSlider)evt.getSource();

    if ( !source.getValueIsAdjusting( )) {
    sl = source.getValue();
    h = sl*sl;
    h2 = h/28;
    h3 = h/30;

    if(evt.getSource() ==jb2);
    ans2 = h3 +"";
    textA.setText(ans2);

    }else{

    ans = h2 +"";
    textA.setText(ans);


    }
    }
    Else is dead .

  15. #35
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    What if is the else paired with?
    In post #33 it looks like the else on line 16 is paired with the if on line 6.
    There is no else for the if on line 12

  16. #36
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    public void stateChanged( ChangeEvent evt )
    {

    JSlider source = (JSlider)evt.getSource();

    if ( !source.getValueIsAdjusting( )) {
    sl = source.getValue();
    h = sl*sl;
    if(evt.getSource() ==jb2){
    h3 = h/30;
    ans2 = h3 +"";
    textA.setText(ans2);

    }else{
    h2 = h/28;
    ans = h2 +"";
    textA.setText(ans);
    }
    }
    }

    this time Else giving the results jb(String) for Female radio button and i set the 1st formula for female and else for male
    now result is male. after click in female button result still male. Saturday 12 Nov is last date I'm tired. please help.

  17. #37
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    public void stateChanged( ChangeEvent evt )
    {

    JSlider source = (JSlider)evt.getSource();

    if ( !source.getValueIsAdjusting( )) {
    sl = source.getValue();
    h = sl*sl;
    if(evt.getSource() ==jb2){
    h3 = h/30;
    ans2 = h3 +"";
    textA.setText(ans2);

    }else{
    h2 = h/28;
    ans = h2 +"";
    textA.setText(ans);
    }
    }
    }

    this time Else giving the results jb(String) for Female radio button and i set the 1st formula for female and else for male
    now result is male. after click in female button result still male. Saturday 12 Nov is last date I'm tired. please help.

  18. #38
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    Where/how does the code you just posted determine if the male or female button is selected?

  19. #39
    baig-sh is offline Member
    Join Date
    Nov 2011
    Posts
    35
    Rep Power
    0

    Default Re: Problem with action performing !!

    public void actionPerformed(ActionEvent ae) {

    if("Female".equals(ae.getActionCommand())) {
    if(f.isSelected() );
    jb2 = f.getText();

    }

  20. #40
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Problem with action performing !!

    How does the code in post #37 determine if the male or female is selected?

    after click in female button result still male
    Where does the code use the male/female selection to determine what the result should be?

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 02-03-2011, 05:19 AM
  2. Replies: 3
    Last Post: 01-11-2011, 11:45 PM
  3. Problem in action listener
    By cool in forum AWT / Swing
    Replies: 4
    Last Post: 11-16-2010, 07:44 AM
  4. problem in action
    By jperson in forum New To Java
    Replies: 2
    Last Post: 07-24-2010, 12:00 PM
  5. Performing Exponentiation in Java without the Math Class
    By BlueJ Coder in forum New To Java
    Replies: 9
    Last Post: 10-14-2009, 08:48 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
  •