Need some help for a application to computation of series parallel circuits!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WanYee
    New Member
    • May 2008
    • 12

    Need some help for a application to computation of series parallel circuits!

    Hi, my name is WanYee, i need some help on an application i am currently doing, the application is like a calculator to find current resistance and etc... of a series-parallel circuit, my problem here is, if i have 2 buttons named "Series" & "Parallel", when the user clicks on "Series" noting happens first, but when i press the button "Calculate" , i want to let my calculate button to use the series formula, how do i let my "Calculate" button knows it. Sorry for my poor explanation.

    Note: I am using Swing, NetBeans IDE 6.1! TY, Help is appreciated!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by WanYee
    Hi, my name is WanYee, i need some help on an application i am currently doing, the application is like a calculator to find current resistance and etc... of a series-parallel circuit, my problem here is, if i have 2 buttons named "Series" & "Parallel", when the user clicks on "Series" noting happens first, but when i press the button "Calculate" , i want to let my calculate button to use the series formula, how do i let my "Calculate" button knows it. Sorry for my poor explanation.

    Note: I am using Swing, NetBeans IDE 6.1! TY, Help is appreciated!
    Read about ActionListeners and the actionPerformed method.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by WanYee
      Hi, my name is WanYee, i need some help on an application i am currently doing, the application is like a calculator to find current resistance and etc... of a series-parallel circuit, my problem here is, if i have 2 buttons named "Series" & "Parallel", when the user clicks on "Series" noting happens first, but when i press the button "Calculate" , i want to let my calculate button to use the series formula, how do i let my "Calculate" button knows it. Sorry for my poor explanation.
      Basically your buttons should be JToggleButtons in a ButtonGroup, i.e. one or
      the other should be 'selected'. Your Calculate button should have a registerd
      ActionListener that checks which of the two first buttons is selected and perform
      the appropriate calculation.

      kind regards,

      Jos

      Comment

      • WanYee
        New Member
        • May 2008
        • 12

        #4
        I know about ActionListener and ActionPerformed , but i do not know how to use the groupButton, i am new to NetBeans, this is actually my school project, and my lecturer asked us to do using NetBeans, which we do not know how to use it, as we use Notepad to learn Java coding, its like so different in NetBeans, so i needed help.

        Thank you, help is going to be really appreciated.

        Comment

        • WanYee
          New Member
          • May 2008
          • 12

          #5
          I have attached how my GUI looks like, please comment and help me, thanks.

          Comment

          • WanYee
            New Member
            • May 2008
            • 12

            #6
            Bump!
            Bump!
            Bump!
            Bump!
            Bump!
            Bump!

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by WanYee
              Bump!
              Bump!
              Bump!
              Bump!
              Bump!
              Bump!
              Have you tried the advice mentioned by Jos above yet?

              Comment

              • WanYee
                New Member
                • May 2008
                • 12

                #8
                Sorry for the bump, i have not tried ButtonGroup, can you like guide me on it, as i am not sure, as i said, my first time using NetBeans, i can't find a guide which really explains on how to use ButtonGroup.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by WanYee
                  Sorry for the bump, i have not tried ButtonGroup, can you like guide me on it, as i am not sure, as i said, my first time using NetBeans, i can't find a guide which really explains on how to use ButtonGroup.
                  We've collected a couple of useful links; download the API documentation from
                  this page.

                  kind regards,

                  Jos

                  Comment

                  • WanYee
                    New Member
                    • May 2008
                    • 12

                    #10
                    Downloading and will read, if i do not understand hope someone will give me an head start of the code or something.

                    Thanks.

                    Comment

                    • WanYee
                      New Member
                      • May 2008
                      • 12

                      #11
                      Jos, Sorry, but i do not still get it on how to use the GroupButton, did you see the attached image i attached, it is the current GUI of my application, i read about the ToggleButton and it says it implements check box and radio button, and in my knowledge, toggle means like the state of 0 when toggled 1 then toggle back to 0 like for binary. Sorry, maybe i am totally all wrong, but i just need a guide on someone to tell me how to do it, to let my calculate button know the state whether is series or parallel last selected.

                      Comment

                      • WanYee
                        New Member
                        • May 2008
                        • 12

                        #12
                        Ok, i got the idea how to use the ButtonGroup, but i still would like to know how do i implement the ActionListener code? I have made my Series/Parallel button grouped to the ButtonGroup.

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by WanYee
                          Ok, i got the idea how to use the ButtonGroup, but i still would like to know how do i implement the ActionListener code? I have made my Series/Parallel button grouped to the ButtonGroup.
                          .

                          Good; if you've used the correct buttons you can see that only one of them is
                          selected; the ButtonGroup takes care of that.

                          Your ActionListener should be a little class attached to that third button and
                          passed one of the series/parallel buttons; suppose you give it the series button;
                          when its actionPerformed () method is called it checks whether or not that
                          series button is selected and acts accordingly.

                          kind regards,

                          Jos

                          Comment

                          • WanYee
                            New Member
                            • May 2008
                            • 12

                            #14
                            What do you mean by third button? The "Calculate" button? Could you like guide me on a head start for it. And yeah, i noticed only one of the button will be selected when i run it.

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by WanYee
                              What do you mean by third button? The "Calculate" button? Could you like guide me on a head start for it.
                              Yes I mean the 'Calculate' button. Your ActionListener can look like this:

                              [code=java]
                              class Calculate implements ActionPerformed {
                              private AbstractButton ab;
                              //
                              public Calculate(JButt on calculate, AbstractButton ab) {
                              this.ab= ab;
                              calculate.addAc tionListener(th is);
                              }
                              //
                              public void actionPerformed (ActionEvent ae) {
                              // calculate something according to the state of ab
                              }
                              }[/code]

                              I think you can manage from here because it's an almost complete giveaway.

                              kind regards,

                              Jos

                              Comment

                              Working...