What's Here?
Members: 306,832
Replies: 841,308
Topics: 140,566
Snippets: 4,465
Tutorials: 1,166
Total Online: 1,747
Members: 122
Guests: 1,625
Loading. Please Wait...
JSpinner, how do i get the info from a jspinner into an output
NewToJava1980
29 Nov, 2008 - 04:34 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
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
CODE
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 Nov, 2008 - 04:44 PM
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 05:04 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(cfoley @ 29 Nov, 2008 - 04:51 PM)
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
CODE
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 Nov, 2008 - 05:16 PM
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 05:51 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(cfoley @ 29 Nov, 2008 - 05:19 PM)
No problem. You've initialised a JSpinner like this:
java
numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1)); When you want the value of that one, just use the line:
java
numberOfBoxesJSpinner.getValue(); that was helpful, but, how do i multiply the numberOfBoxes by the price per box?
I was thinking
CODE
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
QUOTE(NewToJava1980 @ 29 Nov, 2008 - 05:48 PM)
QUOTE(cfoley @ 29 Nov, 2008 - 05:19 PM)
No problem. You've initialised a JSpinner like this:
java
numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1)); When you want the value of that one, just use the line:
java
numberOfBoxesJSpinner.getValue(); that was helpful, but, how do i multiply the numberOfBoxes by the price per box?
I was thinking
CODE
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...
CODE
//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?
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 06:01 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(KYA @ 29 Nov, 2008 - 05:55 PM)
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 Nov, 2008 - 07:06 PM
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 07:17 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(KYA @ 29 Nov, 2008 - 07:02 PM)
I haven't personally used a JSpinner but the following should work:
java
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
CODE
numberOfBoxesJSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 5,1)); numberOfBoxesJSpinner.setBounds(190,40, 50, 20); contentPane.add(numberOfBoxesJSpinner);
and my calculatesubTotal
CODE
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 Nov, 2008 - 07:18 PM
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 07:31 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(KYA @ 29 Nov, 2008 - 07: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
java
public void calculatesubTotal() { int temp = (int) numberOfBoxesJSpinner.getValue(); //type cast subTotal = temp * brandPrice; }inconvertible types...
shananigans....
ok here is the entire code thus far
CODE
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
NewToJava1980
RE: JSpinner 29 Nov, 2008 - 08:15 PM
New D.I.C Head
Joined: 29 Nov, 2008
Posts: 27
QUOTE(KYA @ 29 Nov, 2008 - 07:56 PM)
This compiles
java
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!!!
KYA
RE: JSpinner 30 Nov, 2008 - 11:24 AM
#include <nerd.h>
Joined: 14 Sep, 2007
Posts: 11,489
Thanked: 508 times
Dream Kudos: 2875
Expert In: C, C++, Java
My Contributions
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 Nov, 2008 - 11:29 AM