Solved

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

Posted on 2009-03-28
8
405 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
 

Author Comment

by:duta
ID: 24011759
My question is:

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

Thanks!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now