JSpinner

how do i get the info from a jspinner into an output

Page 1 of 1

14 Replies - 4397 Views - Last Post: 30 November 2008 - 12:24 PM Rate Topic: -----

#1 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

JSpinner

Post icon  Posted 29 November 2008 - 05:34 PM

the program is cigar store basically i need to get info from a spinner to get the total boxes for purchase so i can calculate the subtotal any pointers on how to use a jspinner to get info for a textfield would help


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CigarStore2 extends JFrame
{
	/*------------------------- declarations */

	// color objects

	Color black=new Color(0,0,0);
	Color white=new Color(255,255,255);

	// inputs
	JComboBox brandJComboBox;
	JLabel selectBrandJLabel;

	JSpinner numberOfBoxesJSpinner;
	JLabel numberOfBoxesJLabel;

	JComboBox countyJComboBox;
	JLabel selectCountyJLabel;

	// outputs
	JLabel itemSelectionJLabel;
	JTextField itemSelectionJTextField;

	JLabel brandPriceJLabel;
	JTextField brandPriceJTextField;

	JLabel subTotalJLabel;
	JTextField subTotalJTextField;

	JLabel salesTaxJLabel;
	JTextField salesTaxJTextField;

	JLabel totalSaleJLabel;
	JTextField totalSaleJTextField;


	// controls
	JButton enterJButton;
	JButton clearJButton;
	JButton closeJButton;

	// variables
	String[] BrandArray ={"Europa","Parodi","De Noboli","Petri","Hodura"};
	String[] CountyArray ={"Allegheny","Beaver"};
	int itemIndex;
	String brandName;
	double brandPrice;
	double subTotal;
	double salesTax;
	double totalSale;

	// object classes
	DetermineValue determineValue;

	public CigarStore2()
	{
		createUserInterface();
	}

	public void createUserInterface()
	{
		Container contentPane = getContentPane();
		contentPane.setBackground(white);
		contentPane.setLayout(null);

		/*----------------------- initialize */

		// inputs
		brandJComboBox = new JComboBox(BrandArray);
		brandJComboBox.setBounds(190,10,100,20);
		brandJComboBox.setForeground(black);
		brandJComboBox.setBackground(white);
		brandJComboBox.setMaximumRowCount(5);
		contentPane.add(brandJComboBox);

		selectBrandJLabel = new JLabel();
		selectBrandJLabel.setBounds(80, 10, 100, 20);
		selectBrandJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		selectBrandJLabel.setText("Select Brand:");
		selectBrandJLabel.setForeground(black);
		selectBrandJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(selectBrandJLabel);

		countyJComboBox = new JComboBox(CountyArray);
		countyJComboBox.setBounds(190,70,100,20);
		countyJComboBox.setForeground(black);
		countyJComboBox.setBackground(white);
		countyJComboBox.setMaximumRowCount(2);
		contentPane.add(countyJComboBox);

		selectCountyJLabel = new JLabel();
		selectCountyJLabel.setBounds(80, 70, 100, 20);
		selectCountyJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		selectCountyJLabel.setText("Select County:");
		selectCountyJLabel.setForeground(black);
		selectCountyJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(selectCountyJLabel);

																					//jspinner for number of boxes
		numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));
		numberOfBoxesJSpinner.setBounds(190,40, 50, 20);

		contentPane.add(numberOfBoxesJSpinner);
																					//jlabel for number of boxes
		numberOfBoxesJLabel = new JLabel();
		numberOfBoxesJLabel.setBounds(80, 40, 100, 20);
		numberOfBoxesJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		numberOfBoxesJLabel.setText("Number Of Boxes:");
		numberOfBoxesJLabel.setForeground(black);
		numberOfBoxesJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(numberOfBoxesJLabel);

		// outputs
		itemSelectionJLabel = new JLabel();
		itemSelectionJLabel.setBounds(80, 100, 100, 20);
		itemSelectionJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		itemSelectionJLabel.setText("Selection:");
		itemSelectionJLabel.setForeground(black);
		itemSelectionJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(itemSelectionJLabel);

		itemSelectionJTextField = new JTextField();
		itemSelectionJTextField.setBounds(190, 100, 100, 20);
		itemSelectionJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		itemSelectionJTextField.setHorizontalAlignment(JTextField.CENTER);
		itemSelectionJTextField.setForeground(black);
		itemSelectionJTextField.setBackground(white);
		itemSelectionJTextField.setEditable(false);
		contentPane.add(itemSelectionJTextField);

		brandPriceJLabel = new JLabel();
		brandPriceJLabel.setBounds(80, 130, 100, 20);
		brandPriceJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		brandPriceJLabel.setText("Price Per Box:");
		brandPriceJLabel.setForeground(black);
		brandPriceJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(brandPriceJLabel);

		brandPriceJTextField = new JTextField();
		brandPriceJTextField.setBounds(190, 130, 50, 20);
		brandPriceJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		brandPriceJTextField.setHorizontalAlignment(JTextField.CENTER);
		brandPriceJTextField.setForeground(black);
		brandPriceJTextField.setBackground(white);
		brandPriceJTextField.setEditable(false);
		contentPane.add(brandPriceJTextField);


		subTotalJLabel = new JLabel();
		subTotalJLabel.setBounds(80, 160, 100, 20);
		subTotalJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		subTotalJLabel.setText("SubTotal:");
		subTotalJLabel.setForeground(black);
		subTotalJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(subTotalJLabel);

		subTotalJTextField = new JTextField();
		subTotalJTextField.setBounds(190, 160, 50, 20);
		subTotalJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		subTotalJTextField.setHorizontalAlignment(JTextField.CENTER);
		subTotalJTextField.setForeground(black);
		subTotalJTextField.setBackground(white);
		subTotalJTextField.setEditable(false);
		contentPane.add(subTotalJTextField);

		salesTaxJLabel = new JLabel();
		salesTaxJLabel.setBounds(80, 190, 100, 20);
		salesTaxJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		salesTaxJLabel.setText("Sales Tax:");
		salesTaxJLabel.setForeground(black);
		salesTaxJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(salesTaxJLabel);

		salesTaxJTextField = new JTextField();
		salesTaxJTextField.setBounds(190, 190, 50, 20);
		salesTaxJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		salesTaxJTextField.setHorizontalAlignment(JTextField.CENTER);
		salesTaxJTextField.setForeground(black);
		salesTaxJTextField.setBackground(white);
		salesTaxJTextField.setEditable(false);
		contentPane.add(salesTaxJTextField);


		totalSaleJLabel= new JLabel();
		totalSaleJLabel.setBounds(80, 220, 100, 20);
		totalSaleJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		totalSaleJLabel.setText("Total Sale:");
		totalSaleJLabel.setForeground(black);
		totalSaleJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(totalSaleJLabel);

		totalSaleJTextField= new JTextField();
		totalSaleJTextField.setBounds(190, 220, 50, 20);
		totalSaleJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		totalSaleJTextField.setHorizontalAlignment(JTextField.CENTER);
		totalSaleJTextField.setForeground(black);
		totalSaleJTextField.setBackground(white);
		totalSaleJTextField.setEditable(false);
		contentPane.add(totalSaleJTextField);


		// controls
		enterJButton = new JButton();
		enterJButton.setBounds(10, 300, 100, 20);
		enterJButton.setFont(new Font("Default", Font.PLAIN, 12));
		enterJButton.setText("Enter");
		enterJButton.setForeground(black);
		enterJButton.setBackground(white);
		contentPane.add(enterJButton);
		enterJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					enterJButtonActionPerformed(event);
				}
			}
		);

		clearJButton = new JButton();
		clearJButton.setBounds(130, 300, 100, 20);
		clearJButton.setFont(new Font("Default", Font.PLAIN, 12));
		clearJButton.setText("Clear");
		clearJButton.setForeground(black);
		clearJButton.setBackground(white);
		contentPane.add(clearJButton);
		clearJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					clearJButtonActionPerformed(event);
				}
			}
		);

		closeJButton = new JButton();
		closeJButton.setBounds(240, 300, 100, 20);
		closeJButton.setFont(new Font("Default", Font.PLAIN, 12));
		closeJButton.setText("Close");
		closeJButton.setForeground(black);
		closeJButton.setBackground(white);
		contentPane.add(closeJButton);
		closeJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					closeJButtonActionPerformed(event);
				}
			}
		);

	determineValue = new DetermineValue();

		setTitle("CigarStore2");
		setSize(400, 400);
		setVisible(true);
	}


	// main method
	public static void main(String[] args)
	{
		CigarStore2 application = new CigarStore2();
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void enterJButtonActionPerformed(ActionEvent event)
		{
		itemIndex = brandJComboBox.getSelectedIndex();
		brandName = BrandArray[itemIndex];

		determineValue.setIndexOfValue(itemIndex);
		brandPrice = determineValue.getPricePerBox();
	//	calculatesubTotal();
		displayOutput();
		}
/*	public void calculatesubTotal()
	{
		subTotal = numberOfBoxesJSpinner.getNumberOfBoxes();
		determineValue.setIndexOfValue(itemIndex);
	}
*/
	public void displayOutput()
	{
		itemSelectionJTextField.setText("" + brandName);
		brandPriceJTextField.setText("" + brandPrice);
		//itemNUmberJTextField.setText("" + itemNumberValue);
	}

	public void clearJButtonActionPerformed(ActionEvent event)
	{
	itemSelectionJTextField.setText("");
	brandPriceJTextField.setText("");
	}
	public void closeJButtonActionPerformed(ActionEvent event)
	{
		CigarStore2.this.dispose();
	}


}

class DetermineValue
{
	double []numericValue = {40.95,26.95,34.95,24.50,19.95};
	int valueOfIndex;

	public void setIndexOfValue(int indexValue)
	{
		valueOfIndex = indexValue;
	}
	public double getPricePerBox()
	{
		return numericValue[valueOfIndex];
	}

}


This post has been edited by NewToJava1980: 29 November 2008 - 05:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: JSpinner

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: JSpinner

Posted 29 November 2008 - 05:51 PM

Use the method getValue().
Was This Post Helpful? 0
  • +
  • -

#3 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 06:04 PM

View Postcfoley, on 29 Nov, 2008 - 04:51 PM, said:

Use the method getValue().


maybe I am a fool but, How?

I am not trying to not do this i am just lost, I guess...

getValue() in javax.swing.JSpinner cannot be applied to (javax.swing.JSpinner) I tried this

	public void enterJButtonActionPerformed(ActionEvent event)
		{
		itemIndex = brandJComboBox.getSelectedIndex();
		brandName = BrandArray[itemIndex];

		determineValue.setIndexOfValue(itemIndex);
		brandPrice = determineValue.getPricePerBox();

		calculatesubTotal();
	//	calculatesalesTax();
		displayOutput();
		}


	public void calculatesubTotal()
	{
		subTotal = numberOfBoxesJSpinner.getValue(numberOfBoxesJSpinner);
		determineValue.setIndexOfValue(itemIndex);
	}


This post has been edited by NewToJava1980: 29 November 2008 - 06:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: JSpinner

Posted 29 November 2008 - 06:19 PM

No problem. You've initialised a JSpinner like this:

numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));


When you want the value of that one, just use the line:

numberOfBoxesJSpinner.getValue();

Was This Post Helpful? 1
  • +
  • -

#5 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 06:51 PM

View Postcfoley, on 29 Nov, 2008 - 05:19 PM, said:

No problem. You've initialised a JSpinner like this:

numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));


When you want the value of that one, just use the line:

numberOfBoxesJSpinner.getValue();



that was helpful, but, how do i multiply the numberOfBoxes by the price per box?

I was thinking
		subTotal = (numberOfBoxesJSpinner.getValue()) * brandPrice;



hmm, as i look at it, it doesn't make sense... and of course i get an error...

operator * cannot be applied to java.lang.Object,double

View PostNewToJava1980, on 29 Nov, 2008 - 05:48 PM, said:

View Postcfoley, on 29 Nov, 2008 - 05:19 PM, said:

No problem. You've initialised a JSpinner like this:

numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));


When you want the value of that one, just use the line:

numberOfBoxesJSpinner.getValue();



that was helpful, but, how do i multiply the numberOfBoxes by the price per box?

I was thinking
		subTotal = (numberOfBoxesJSpinner.getValue()) * brandPrice;



hmm, as i look at it, it doesn't make sense... and of course i get an error...

operator * cannot be applied to java.lang.Object,double



wait just referred to my notes i think i may have figured it out...
		//get Input
		firstNumber = Integer.parseInt(firstNumberJTextField.getText());
		secondNumber = Integer.parseInt(secondNumberJTextField.getText());	
		
		//add Numbers
		finalNumber = firstNumber + secondNumber;
		
		displayResults();
		



just got to adjust for my current scheme... right?
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: JSpinner

Posted 29 November 2008 - 06:55 PM

Or assign a temp double variable to spinner.getValue() then multiply it by brandPrice.
Was This Post Helpful? 0
  • +
  • -

#7 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 07:01 PM

View PostKYA, on 29 Nov, 2008 - 05:55 PM, said:

Or assign a temp double variable to spinner.getValue() then multiply it by brandPrice.

how would that work?

i have been at this for two hours now and i feel i am getting nowhere...

This post has been edited by NewToJava1980: 29 November 2008 - 08:06 PM

Was This Post Helpful? 0
  • +
  • -

#8 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: JSpinner

Posted 29 November 2008 - 08:02 PM

I haven't personally used a JSpinner but the following should work:

double temp = numberOfBoxesJSpinner.getValue();
 subTotal = temp * brandPrice;



edit: Your spinner is filled with doubles right? If it keeps returning just "Object" type cast it to a double.

This post has been edited by KYA: 29 November 2008 - 08:03 PM

Was This Post Helpful? 0
  • +
  • -

#9 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 08:17 PM

View PostKYA, on 29 Nov, 2008 - 07:02 PM, said:

I haven't personally used a JSpinner but the following should work:

double temp = numberOfBoxesJSpinner.getValue();
 subTotal = temp * brandPrice;



edit: Your spinner is filled with doubles right? If it keeps returning just "Object" type cast it to a double.


ahh no?
spinner
		numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));
		numberOfBoxesJSpinner.setBounds(190,40, 50, 20);

		contentPane.add(numberOfBoxesJSpinner);



and my calculatesubTotal
	public void calculatesubTotal()
	{
	double temp = numberOfBoxesJSpinner.getValue();
   	subTotal = temp * brandPrice;

	}


i get an error code
incompatible types
am i doing something wrong?

This post has been edited by NewToJava1980: 29 November 2008 - 08:18 PM

Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: JSpinner

Posted 29 November 2008 - 08:21 PM

Ok so based on your declaration it holds integers. edit: Or at least it holds 0-5 steps in 1 increments so integers

public void calculatesubTotal()
    {
    int temp = (int) numberOfBoxesJSpinner.getValue(); //type cast
       subTotal = temp * brandPrice;

    }


This post has been edited by KYA: 29 November 2008 - 08:22 PM

Was This Post Helpful? 0
  • +
  • -

#11 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 08:31 PM

View PostKYA, on 29 Nov, 2008 - 07:21 PM, said:

Ok so based on your declaration it holds integers. edit: Or at least it holds 0-5 steps in 1 increments so integers

public void calculatesubTotal()
    {
    int temp = (int) numberOfBoxesJSpinner.getValue(); //type cast
       subTotal = temp * brandPrice;

    }


inconvertible types...

shananigans....
ok here is the entire code thus far
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.awt.*;
import java.util.*;

public class CigarStore2 extends JFrame
{
	/*------------------------- declarations */

	// color objects

	Color black=new Color(0,0,0);
	Color white=new Color(255,255,255);

	// inputs
	JComboBox brandJComboBox;
	JLabel selectBrandJLabel;

	JSpinner numberOfBoxesJSpinner;
	JLabel numberOfBoxesJLabel;

	JComboBox countyJComboBox;
	JLabel selectCountyJLabel;

	// outputs
	JLabel itemSelectionJLabel;
	JTextField itemSelectionJTextField;

	JLabel brandPriceJLabel;
	JTextField brandPriceJTextField;

	JLabel subTotalJLabel;
	JTextField subTotalJTextField;

	JLabel salesTaxJLabel;
	JTextField salesTaxJTextField;

	JLabel totalSaleJLabel;
	JTextField totalSaleJTextField;


	// controls
	JButton enterJButton;
	JButton clearJButton;
	JButton closeJButton;

	// variables
	String[] BrandArray ={"Europa","Parodi","De Noboli","Petri","Hodura"};
	String[] CountyArray ={"Allegheny","Beaver"};
	int itemIndex;
	String brandName;
	double brandPrice;
	double subTotal;
	double salesTax;
	double totalSale;
	double spinnerValue;

	// object classes
	DetermineValue determineValue;

	public CigarStore2()
	{
		createUserInterface();
	}

	public void createUserInterface()
	{
		Container contentPane = getContentPane();
		contentPane.setBackground(white);
		contentPane.setLayout(null);

		/*----------------------- initialize */

		// inputs
		brandJComboBox = new JComboBox(BrandArray);
		brandJComboBox.setBounds(190,10,100,20);
		brandJComboBox.setForeground(black);
		brandJComboBox.setBackground(white);
		brandJComboBox.setMaximumRowCount(5);
		contentPane.add(brandJComboBox);

		selectBrandJLabel = new JLabel();
		selectBrandJLabel.setBounds(80, 10, 100, 20);
		selectBrandJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		selectBrandJLabel.setText("Select Brand:");
		selectBrandJLabel.setForeground(black);
		selectBrandJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(selectBrandJLabel);

		countyJComboBox = new JComboBox(CountyArray);
		countyJComboBox.setBounds(190,70,100,20);
		countyJComboBox.setForeground(black);
		countyJComboBox.setBackground(white);
		countyJComboBox.setMaximumRowCount(2);
		contentPane.add(countyJComboBox);

		selectCountyJLabel = new JLabel();
		selectCountyJLabel.setBounds(80, 70, 100, 20);
		selectCountyJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		selectCountyJLabel.setText("Select County:");
		selectCountyJLabel.setForeground(black);
		selectCountyJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(selectCountyJLabel);

																					//jspinner for number of boxes
		numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1));
		numberOfBoxesJSpinner.setBounds(190,40, 50, 20);

		contentPane.add(numberOfBoxesJSpinner);
																					//jlabel for number of boxes
		numberOfBoxesJLabel = new JLabel();
		numberOfBoxesJLabel.setBounds(80, 40, 100, 20);
		numberOfBoxesJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		numberOfBoxesJLabel.setText("Number Of Boxes:");
		numberOfBoxesJLabel.setForeground(black);
		numberOfBoxesJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(numberOfBoxesJLabel);

		// outputs
		itemSelectionJLabel = new JLabel();
		itemSelectionJLabel.setBounds(80, 100, 100, 20);
		itemSelectionJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		itemSelectionJLabel.setText("Selection:");
		itemSelectionJLabel.setForeground(black);
		itemSelectionJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(itemSelectionJLabel);

		itemSelectionJTextField = new JTextField();
		itemSelectionJTextField.setBounds(190, 100, 100, 20);
		itemSelectionJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		itemSelectionJTextField.setHorizontalAlignment(JTextField.CENTER);
		itemSelectionJTextField.setForeground(black);
		itemSelectionJTextField.setBackground(white);
		itemSelectionJTextField.setEditable(false);
		contentPane.add(itemSelectionJTextField);

		brandPriceJLabel = new JLabel();
		brandPriceJLabel.setBounds(80, 130, 100, 20);
		brandPriceJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		brandPriceJLabel.setText("Price Per Box:");
		brandPriceJLabel.setForeground(black);
		brandPriceJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(brandPriceJLabel);

		brandPriceJTextField = new JTextField();
		brandPriceJTextField.setBounds(190, 130, 50, 20);
		brandPriceJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		brandPriceJTextField.setHorizontalAlignment(JTextField.CENTER);
		brandPriceJTextField.setForeground(black);
		brandPriceJTextField.setBackground(white);
		brandPriceJTextField.setEditable(false);
		contentPane.add(brandPriceJTextField);


		subTotalJLabel = new JLabel();
		subTotalJLabel.setBounds(80, 160, 100, 20);
		subTotalJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		subTotalJLabel.setText("SubTotal:");
		subTotalJLabel.setForeground(black);
		subTotalJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(subTotalJLabel);

		subTotalJTextField = new JTextField();
		subTotalJTextField.setBounds(190, 160, 50, 20);
		subTotalJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		subTotalJTextField.setHorizontalAlignment(JTextField.CENTER);
		subTotalJTextField.setForeground(black);
		subTotalJTextField.setBackground(white);
		subTotalJTextField.setEditable(false);
		contentPane.add(subTotalJTextField);

		salesTaxJLabel = new JLabel();
		salesTaxJLabel.setBounds(80, 190, 100, 20);
		salesTaxJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		salesTaxJLabel.setText("Sales Tax:");
		salesTaxJLabel.setForeground(black);
		salesTaxJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(salesTaxJLabel);

		salesTaxJTextField = new JTextField();
		salesTaxJTextField.setBounds(190, 190, 50, 20);
		salesTaxJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		salesTaxJTextField.setHorizontalAlignment(JTextField.CENTER);
		salesTaxJTextField.setForeground(black);
		salesTaxJTextField.setBackground(white);
		salesTaxJTextField.setEditable(false);
		contentPane.add(salesTaxJTextField);


		totalSaleJLabel= new JLabel();
		totalSaleJLabel.setBounds(80, 220, 100, 20);
		totalSaleJLabel.setFont(new Font("Default", Font.PLAIN, 12));
		totalSaleJLabel.setText("Total Sale:");
		totalSaleJLabel.setForeground(black);
		totalSaleJLabel.setHorizontalAlignment(JLabel.RIGHT);
		contentPane.add(totalSaleJLabel);

		totalSaleJTextField= new JTextField();
		totalSaleJTextField.setBounds(190, 220, 50, 20);
		totalSaleJTextField.setFont(new Font("Default", Font.PLAIN, 12));
		totalSaleJTextField.setHorizontalAlignment(JTextField.CENTER);
		totalSaleJTextField.setForeground(black);
		totalSaleJTextField.setBackground(white);
		totalSaleJTextField.setEditable(false);
		contentPane.add(totalSaleJTextField);


		// controls
		enterJButton = new JButton();
		enterJButton.setBounds(10, 300, 100, 20);
		enterJButton.setFont(new Font("Default", Font.PLAIN, 12));
		enterJButton.setText("Enter");
		enterJButton.setForeground(black);
		enterJButton.setBackground(white);
		contentPane.add(enterJButton);
		enterJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					enterJButtonActionPerformed(event);
				}
			}
		);

		clearJButton = new JButton();
		clearJButton.setBounds(130, 300, 100, 20);
		clearJButton.setFont(new Font("Default", Font.PLAIN, 12));
		clearJButton.setText("Clear");
		clearJButton.setForeground(black);
		clearJButton.setBackground(white);
		contentPane.add(clearJButton);
		clearJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					clearJButtonActionPerformed(event);
				}
			}
		);

		closeJButton = new JButton();
		closeJButton.setBounds(240, 300, 100, 20);
		closeJButton.setFont(new Font("Default", Font.PLAIN, 12));
		closeJButton.setText("Close");
		closeJButton.setForeground(black);
		closeJButton.setBackground(white);
		contentPane.add(closeJButton);
		closeJButton.addActionListener(

			new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					closeJButtonActionPerformed(event);
				}
			}
		);

	determineValue = new DetermineValue();

		setTitle("CigarStore2");
		setSize(400, 400);
		setVisible(true);
	}


	// main method
	public static void main(String[] args)
	{
		CigarStore2 application = new CigarStore2();
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void enterJButtonActionPerformed(ActionEvent event)
		{
		itemIndex = brandJComboBox.getSelectedIndex();
		brandName = BrandArray[itemIndex];

		determineValue.setIndexOfValue(itemIndex);
		brandPrice = determineValue.getPricePerBox();

		calculatesubTotal();
	}

   public void calculatesubTotal()
	   {
	   int temp = (int) numberOfBoxesJSpinner.getValue(); //type cast
	   subTotal = temp * brandPrice;

	   }

	public void displayOutput()
	{
		itemSelectionJTextField.setText("" + brandName);
		brandPriceJTextField.setText("" + brandPrice);
		subTotalJTextField.setText("" + subTotal );
	}

	public void clearJButtonActionPerformed(ActionEvent event)
	{
	itemSelectionJTextField.setText("");
	brandPriceJTextField.setText("");
	subTotalJTextField.setText("");
	}
	public void closeJButtonActionPerformed(ActionEvent event)
	{
		CigarStore2.this.dispose();
	}


}

class DetermineValue
{
	double []numericValue = {40.95,26.95,34.95,24.50,19.95};
	int valueOfIndex;

	public void setIndexOfValue(int indexValue)
	{
		valueOfIndex = indexValue;
	}
	public double getPricePerBox()
	{
		return numericValue[valueOfIndex];
	}


}



I really appreciate everyone's help
Was This Post Helpful? 0
  • +
  • -

#12 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: JSpinner

Posted 29 November 2008 - 08:56 PM

This compiles

public void calculatesubTotal()
{
        Object temp =  numberOfBoxesJSpinner.getValue();
        int num = Integer.parseInt(""+temp);
       subTotal = num * brandPrice;

}



edit: It works, just have to call displayOutput() after sub totaling :)

This post has been edited by KYA: 29 November 2008 - 08:58 PM

Was This Post Helpful? 1
  • +
  • -

#13 NewToJava1980  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-November 08

Re: JSpinner

Posted 29 November 2008 - 09:15 PM

View PostKYA, on 29 Nov, 2008 - 07:56 PM, said:

This compiles

public void calculatesubTotal()
{
        Object temp =  numberOfBoxesJSpinner.getValue();
        int num = Integer.parseInt(""+temp);
       subTotal = num * brandPrice;

}



edit: It works, just have to call displayOutput() after sub totaling :)

thanks i hope i have better luck with the rest of the program!!!
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,910
  • Joined: 06-March 08

Re: JSpinner

Posted 29 November 2008 - 11:55 PM

View PostNewToJava1980, on 29 Nov, 2008 - 08:15 PM, said:

public void calculatesubTotal()
{
        Object temp =  numberOfBoxesJSpinner.getValue();
        int num = Integer.parseInt(""+temp);
       subTotal = num * brandPrice;

}


This is not valid Java code .... won't compile
What are you trying to do ?
Was This Post Helpful? 0
  • +
  • -

#15 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: JSpinner

Posted 30 November 2008 - 12:24 PM

Yes it will and it does. getValue() returns an object. For whatever reason, java won't let me do an easy type cast. So I parsed the integer from the object and performed the calculations.


JSpinner.getValue(), Earlier in the thread, we tried C style casting, but apparently that is illegal if an Object is getting returned. It should return an Integer (at least I think that), but it doesn't. I think its an acceptable workaround for the time being.

edited for typos

This post has been edited by KYA: 30 November 2008 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1