Page 3 of 3 FirstFirst 123
Results 41 to 53 of 53
Like Tree2Likes

Thread: Problem with action performing !!

  1. #41
    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);
    }
    }
    }

  2. #42
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    Why did you post this code? You need to have comments with your posts that say what you are trying to do.
    Can you add comments to your code describing what it is doing
    The variable names do NOT carry any meaning. These are poor variable names: jb2 and h2 What data do they contain? You should name variables with a name that describes the data they contain.

    Also what are the values 28 and 30 ? What do they represent?

  3. #43
    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);
    }
    }
    }

  4. #44
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    Why did you post this code? You need to have comments with your posts that say what you are trying to do.
    Can you add comments to your code describing what it is doing
    The variable names do NOT carry any meaning. These are poor variable names: jb2 and h2 What data do they contain? You should name variables with a name that describes the data they contain.

    Also what are the values 28 and 30 ? What do they represent?

    Also your code formatting is bad. You should indent the code within each pair of {}s to show that its nesting/scope levels.
    Look at post #33 for an example.
    Last edited by Norm; 11-10-2011 at 06:54 PM.

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

    Default Re: Problem with action performing !!

    Male ideal weight
    Height*height/28

    Height*height/30 (for female)

    sl Slider value
    h = heaight*height (sl*sl)

    h2 = h/28 (male weight)

    h3 = h/30 (female weight)

    jb2 is String for female JRadion Button

  6. #46
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    You seem to be having a problem adding comments to your code. Is that because you have a problem with English?
    Does Google translate work for your language? If so, can you type your questions in your language into google translator and have it converted to English?

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

    Default Re: Problem with action performing !!

    Java Code:
    public void stateChanged( ChangeEvent evt )
      {
     
       JSlider source = (JSlider)evt.getSource();
            
        if ( !source.getValueIsAdjusting( )) {
        sl = source.getValue();
        h = sl*sl;
    }  // End of  if line 6
    
    if(evt.getSource() ==jb2){
       h3 = h/30;
     ans2 = h3 +"";
    textA.setText(ans2);
     
    }else {
      h2 = h/28;
    ans = h2 +"";
    textA.setText(ans);
         } // End of else for IF line 12
    
        // cut } form here and pasted up on line 11 under h3 = h/30 e.g (according to post #33)
    
     }
    i changed the } code compile and app run successfully but result is same like past.
    Last edited by Norm; 11-10-2011 at 07:35 PM. Reason: added cod tags

  8. #48
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    Where does the code just posted (#47) decide if male or female is selected?

    I've asked this question 3 times now. See #38 and #40
    Last edited by Norm; 11-10-2011 at 07:43 PM.

  9. #49
    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() ); // f is name of JRadio buttom "Female" is setActionCommand("Female"), m is name of male button
    jb2 = f.getText();

    }
    } // end of action performed

    public void stateChanged( ChangeEvent evt )
    {

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

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

    }else {
    h2 = h/28;
    ans = h2 +"";
    textA.setText(ans);
    } // End of else for IF line 12

    }

  10. #50
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    One last time and then I'll leave this thread for some one else.
    Where does the code just posted (#47 & #49) decide if male or female is selected?

    Give your explanation in English.

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

    Default Re: Problem with action performing !!

    Dear norm,

    i haven't word for you and your kindness. I Appreciate your rating is much high.you tried to guide me as its possible.
    unfortunately i couldn't understand. You are really a great person and good teacher.
    i think i posted here i things who i have even full code. I know you are not engage for me but you tried your best
    what is & something wrong with me now i m out of total empty and confuse.
    thanks again.
    Regards
    Baig

  12. #52
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with action performing !!

    You need to look at how your code detects whether male or female is selected. You say that your tests are not working.
    What is jb2? Why do you compare it to the source of the event when the slider changes? The source of the event for the slider changing will be the slider.

    Add System.outprintlns to print out the value of jb2 and the value of the event's source.

  13. #53
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

Page 3 of 3 FirstFirst 123

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
  •