Solved

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

Posted on 2009-03-28
8
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

696 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