Solved

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

Posted on 2009-03-28
8
409 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 47
How to determine if a string is a valid SHA value 7 35
Bot application - advice 3 38
collection output issue 9 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

856 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