473,474 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

12 New Member
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!
May 18 '08 #1
20 2111
r035198x
13,262 MVP
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.
May 18 '08 #2
JosAH
11,448 Recognized Expert MVP
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
May 18 '08 #3
WanYee
12 New Member
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.
May 18 '08 #4
WanYee
12 New Member
I have attached how my GUI looks like, please comment and help me, thanks.

May 18 '08 #5
WanYee
12 New Member
Bump!
Bump!
Bump!
Bump!
Bump!
Bump!
May 19 '08 #6
r035198x
13,262 MVP
Bump!
Bump!
Bump!
Bump!
Bump!
Bump!
Have you tried the advice mentioned by Jos above yet?
May 19 '08 #7
WanYee
12 New Member
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.
May 19 '08 #8
JosAH
11,448 Recognized Expert MVP
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
May 19 '08 #9
WanYee
12 New Member
Downloading and will read, if i do not understand hope someone will give me an head start of the code or something.

Thanks.
May 19 '08 #10
WanYee
12 New Member
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.
May 19 '08 #11
WanYee
12 New Member
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.
May 19 '08 #12
JosAH
11,448 Recognized Expert MVP
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
May 19 '08 #13
WanYee
12 New Member
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.
May 19 '08 #14
JosAH
11,448 Recognized Expert MVP
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:

Expand|Select|Wrap|Line Numbers
  1. class Calculate implements ActionPerformed {
  2.    private AbstractButton ab;
  3.    //
  4.    public Calculate(JButton calculate, AbstractButton ab) {
  5.       this.ab= ab;
  6.       calculate.addActionListener(this);
  7.    }
  8.    //
  9.    public void actionPerformed(ActionEvent ae) {
  10.       // calculate something according to the state of ab
  11.    }
  12. }
I think you can manage from here because it's an almost complete giveaway.

kind regards,

Jos
May 19 '08 #15
WanYee
12 New Member
But, where does AbstractButton comes from, or it is just an example, cause now i have them group, my idea was like
Expand|Select|Wrap|Line Numbers
  1. if(e.getSource()==jbSeries)
  2.         {
  3. seriescalculations;
  4.         }
  5.         else if(e.getSource()==jbParallel)
  6.         {
  7. parallelcalculations;
  8.         }
May 19 '08 #16
JosAH
11,448 Recognized Expert MVP
But, where does AbstractButton comes from, or it is just an example, cause now i have them group, my idea was like
Expand|Select|Wrap|Line Numbers
  1. if(e.getSource()==jbSeries)
  2.         {
  3. seriescalculations;
  4.         }
  5.         else if(e.getSource()==jbParallel)
  6.         {
  7. parallelcalculations;
  8.         }
Why do you want to register an ActionListener to the parallel/series buttons?
Think what a user does: s/he selects one of them (nothing is supposed to happen)
and *then* the user presses the Calculate button. The ActionListener for that
button isn't interested what the user had done before because exactly one of
the parallel/series buttons is selected. The ButtonGroup object took care of that.
All it has to do is inspect which one is selected and perform its calculations.
That's exactly what my class skeleton does and it doesn't care what button you
are using so it uses the upper most super class for that.

kind regards,

Jos
May 19 '08 #17
WanYee
12 New Member
But i don't really know how to use yours, sorry. I am researching on it soon, and NetBeans i can't type codes in it, i have to use set event to it then customize code, or am i coding in the wrong way, please guide me, thanks.
May 19 '08 #18
JosAH
11,448 Recognized Expert MVP
But i don't really know how to use yours, sorry. I am researching on it soon, and NetBeans i can't type codes in it, i have to use set event to it then customize code, or am i coding in the wrong way, please guide me, thanks.
Well, research my proposal first then and come back when you have an idea
how it works or should work. Turning proposals down or ignoring them just because
you don't know how they work is not the way to go; the way you're coding now
is completely off track IMHO.

kind regards,

Jos
May 19 '08 #19
WanYee
12 New Member
Yeah, i know, i actually just started learning coding in Java for 2 weeks only, i will do up more research base on what you gave. Thanks, i am desperate because this is a project and the only part i am stuck is this part.

By the way, i stated i am not sure how to do it in NetBeans your way, maybe could you like guide/explain to me, cause NetBeans has so much thing i can't add or edit, i have to customize code to edit the codes.
May 19 '08 #20
JosAH
11,448 Recognized Expert MVP
Yeah, i know, i actually just started learning coding in Java for 2 weeks only, i will do up more research base on what you gave. Thanks, i am desperate because this is a project and the only part i am stuck is this part.

By the way, i stated i am not sure how to do it in NetBeans your way, maybe could you like guide/explain to me, cause NetBeans has so much thing i can't add or edit, i have to customize code to edit the codes.
That can't be the meaning of an IDE such as NetBeans. Why don't you simply
edit your .java files using a simple text editor and compile and run your classes
using the 'javac' and 'java' command line tools? Now NetBeans is more of a
hindrance to you than any help.

kind regards,

Jos
May 19 '08 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: MS | last post by:
I have client sever application my client is windows based thin application and server has webService running. Right now Server serialized the data to the client using "XMLSerialization" form data...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
23
by: Simon Wittber | last post by:
I've just bought a new notebook, which has a dual core CPU. I write cross platform games in Python, and I'd really like to be able to use this second core (on my machine, and on user's machines)...
43
by: parallelpython | last post by:
Has anybody tried to run parallel python applications? It appears that if your application is computation-bound using 'thread' or 'threading' modules will not get you any speedup. That is because...
4
by: skatemore9690 | last post by:
#1 in Calculus you learned that log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + ... for x in the interval (-1,1] (here x^2 means "x squared", etc.). Write a program which asks the user to type a...
15
by: Bjoern Schliessmann | last post by:
Hello all, I'm trying to simulate simple electric logic (asynchronous) circuits. By "simple" I mean that I only want to know if I have "current" or "no current" (it's quite digital) and the only...
1
by: ShadowZone | last post by:
When i ported some simple computation program from c++ to c# i've found out that it works much more slower. I expected that because of using generics instead of pointers which are considered "unsafe"...
4
by: id.engg | last post by:
logFileName = 'log.txt' logfile = open(logFileName, "a") class MyUDPServer(SocketServer.UDPServer): def server_bind(self): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8388608)...
5
by: truptivk | last post by:
Hello all, I have a question and I'd be glad if any of you could help me :) I have written code to add rows dynamically to an existing table. When the user first comes to the page, there are 2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.