?
Solved

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

Posted on 2009-03-28
8
Medium Priority
?
416 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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