Solved

JAVA:  How to combine  inpts from CheckBox listeners, RadioBox listeners and Button Listeners?

Posted on 2009-03-28
8
407 Views
Last Modified: 2012-05-06
Dear experts:

I have three different types of listeners : 1) Radio Button listeners (2) Check Box listeners (3) Button listeners, in addition to Text Fields.

I need to combine the inputs and selections from the objects and compute.

How to combine and compute?

I know how to compute in an individual listener class.

Thank you very much in advance!
0
Comment
Question by:duta
  • 5
  • 2
8 Comments
 

Author Comment

by:duta
ID: 24011652
For instance,  radio button has two choices:  (1)  1 topping ($1.5)  (2_  2 toppings ($3)   (3) 3 toppings ($5)
                      check boxes  has three choices: (1)  vegie pizza ($9)  (2) thick-pan pizza ($9)  (3)  Italian      pizza ($11)
                     text fields takes  quantity of order

I would like to compute total amount of each order.

0
 
LVL 15

Expert Comment

by:fsze88
ID: 24011664
um... try to implements WindowListener,ActionListener
and add
public void actionPerformed(ActionEvent e) {
//  somethings what you needs
//  you can do something for each object by         e.getClass().getName();,         e.getSource();
}
example http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

or calling same void from each listener
JCheckBox.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { same_ActionPerformed( ae ); } } );
0
 

Author Comment

by:duta
ID: 24011691
I already know how to create and register the listeners.

What I would like to know is:
how to compute the user inputs collected by the three different listener classes.

For instance, (from my earlier post),  a client chose two toppings (from Radio Button listener),  vegie pizza (from Check Boxes),  3 pizzas (from Text Field ).

Where and how may I combine and compute  the client's order?   In one of the three listener classes?

Thanks!
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:duta
ID: 24011759
My question is:

How to get access from  ButtonListner)  to RadioButton Listner or CheckBox Listener?

Thanks!
0
 
LVL 92

Expert Comment

by:objects
ID: 24011931
you don't need to collect the inputs in your listener as you listener can simply get the gui control status directly from the control.
for example if it needs the state of a checkbox, you just get it directly from the checkbox

0
 

Author Comment

by:duta
ID: 24011970
Savant, thank you very much.

I have a situation similar to the following scenario:
________________________________________
For instance,  radio button has two choices:  (1)  1 topping ($1.5)  (2_  2 toppings ($3)   (3) 3 toppings ($5)
                      check boxes  has three choices: (1)  vegie pizza ($9)  (2) thick-pan pizza ($9)  (3)  Italian      pizza ($11)
                     text fields takes  quantity of order

I would like to compute total amount of each order.
__________________________________________________________

I need to compute the invoice amount.

How can I make the computation from the user  pressing the radio button, check box?

Thanks a lot!
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24011992

be something like:

if (rb1.isSelected()) cost += 1.5;
else if (rb2.isSelected()) cost += 3;
else if (rb3.isSelected()) cost += 45;

if (cb1.isSelected()) cost += 9;
if (cb2.isSelected()) cost += 9;
if (cb3.isSelected()) cost += 11;

cost *= Integer.parseInt(quantityField.getText());

0
 

Author Closing Comment

by:duta
ID: 31563983
Thank you so much, Savant!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question