User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 403,513 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,054 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting

JComboBox

Join Date: Aug 2007
Posts: 57
Reputation: NycNessyness is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

JComboBox

  #1  
May 16th, 2008
Hello. I'm having troubles with my JComboBox calculations. For example, if the strings in my JComboBox were String[] name = { "John", "Tom" }; And Tom was assigned 15% to his name. How can I have the cases in my action performed reach out to a calculation class to perform the calculation. What I want to do is have a total of the percent and amount added in a JTextfield to display in another JTextField. So basically the user is selecting a person, which has a certain percent assigned to the name depending on the person. Then the % is multiplied by a number from another textfield. The part I'm trying to figure out is how to display the total in another JTextfield depending on the person selected. If they pick case 0, it will only show John's amount in the totalField or if they pick Tom, it will only show Tom's amount in the totalField. What is the best way I can do this. I know how to do the calculations, it's the displaying part that I'm finding difficult. I left out alot of stuff, I'm just using this as an example. Thanks for hearing me out.


public void actionPerformed(ActionEvent e)
{
   if(e.getSource() == nameCombo)
		{
			switch(nameCombo.getSelectedIndex())
			{
				case 0:
					break;
				case 1:
					break;
				
			}

		}

}

 private void calc()
     {

		double dollarNumber = 00;
                double totalNumber = 00;

		dollarNumber = Double.parseDouble(dollarField.getText());
		


		total = dollarNumber * johnPercent;
		total = dollarNumber * tomPercent;

		totalField.setText("$" + totalNumber);
		damtDisplay.setText("" + total);
	

 	 }
Last edited by NycNessyness : May 16th, 2008 at 4:39 am. Reason: Messed up syntax
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 12:52 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC