1 Attachment(s)
Getting selected values from a form
Hi,
i have constructed a JFrame for a computer shop (an assignment)the user has to select the components needed relating to buying a laptop or a desktop. When he/she has selected these the price of each is then totalled up and the total displayed on the screen.
Each component is presented either as a menu item or combobox.
I am not sure as to how to "get" the prices to add them up? I have at present the values in a table for a desktop CPU, and a laptop cpu with a view to adding all other component prices so that the prices are all in one place in a JTable.
The total price is displayed when the user presses the submit button.
I have also attached the file so that you can see properly what i am trying to do.
Code:
package ecsecomputers;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
/**
*
* @author
*/
public class ShopFrame extends javax.swing.JFrame {
/** Creates new form ShopFrame */
public ShopFrame() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][]
{
{"Intel", "Core II Duo", "2200", "54.99", "Intel ", "Centrino", "1800", "149,99"},
{"Intel", "Quad Core", "3000", "179.99", "Intel ", "Centrino II", "2000", "179.99"},
{"Intel", "Pentium", "1800", "47.99", "Intel", "Core i3", "2200", "165.99"},
{"Intel", "Celeron", "1800", "34.99", "Intel ", "Core i5", "2200", "176.99"},
{"Intel", "Atom", "1400", "68.99", "Intel ", "Core i7", "2800", "199.99"},
{"AMD", "Phenom", "3000", "123.99", "AMD", "Turion II Dual Core", "2000", "145.99"},
{"AMD", "Athlon", "3000", "99.95", "AMD", "Athlon II Dual Core", "2400", "148.95"},
{"AMD", "Sempron", "2000", "38.99", "AMD", "V Series", "1800", "165.99"},
new String [] {"Brand", "Type", "Speed GHz", "Price £", "Brand", "Type", "Speed GHz", "Price £" } )
}// </editor-fold>
private void bSubmitActionPerformed(java.awt.event.ActionEvent evt) {
// YOUR CODE HERE....
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ShopFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
javax.swing.JLabel TitleLB;
javax.swing.JButton bSubmit;
javax.swing.JComboBox cbDeskprocessor;
javax.swing.JComboBox cbDesktopspeed;
javax.swing.JComboBox cbLaptopcpu;
javax.swing.JComboBox cbLaptopspeed;
javax.swing.JLabel jLabel1;
javax.swing.JLabel jLabel2;
javax.swing.JScrollPane jScrollPane1;
javax.swing.JScrollPane jScrollPane2;
javax.swing.JSeparator jSeparator1;
javax.swing.JTable jTable1;
javax.swing.JTextArea jTextArea1;
javax.swing.JLabel lbDesktopcpu;
javax.swing.JLabel lbLaptopcpu;
javax.swing.JLabel lbProcessorspeed1;
javax.swing.JLabel lbProcessorspeed2;
javax.swing.JMenuBar menuBar;
javax.swing.JMenu muAboutus;
javax.swing.JMenu muComponents;
javax.swing.JMenu muContact;
javax.swing.JMenu muDesktop;
javax.swing.JMenu muHelp;
javax.swing.JMenu muHome;
javax.swing.JMenu muIndex;
javax.swing.JMenu muLaptop;
javax.swing.JMenu muShoppingcart;
javax.swing.JPanel pCpupanel;
javax.swing.JRadioButtonMenuItem rbDeskcase;
javax.swing.JRadioButtonMenuItem rbDeskcdrom;
javax.swing.JRadioButtonMenuItem rbDeskchipset;
javax.swing.JRadioButtonMenuItem rbDeskcpu;
javax.swing.JRadioButtonMenuItem rbDeskdvdrewriter;
javax.swing.JRadioButtonMenuItem rbDeskgraphics;
javax.swing.JRadioButtonMenuItem rbDeskheatsink;
javax.swing.JRadioButtonMenuItem rbDeskmemory;
javax.swing.JRadioButtonMenuItem rbDeskmonitor;
javax.swing.JRadioButtonMenuItem rbDeskmotherboard;
javax.swing.JRadioButtonMenuItem rbDeskpsu;
javax.swing.JRadioButtonMenuItem rbDesksound;
javax.swing.JRadioButtonMenuItem rbLapbattery;
javax.swing.JRadioButtonMenuItem rbLapcase;
javax.swing.JRadioButtonMenuItem rbLapchassis;
javax.swing.JRadioButtonMenuItem rbLapchipset;
javax.swing.JRadioButtonMenuItem rbLapcpu;
javax.swing.JRadioButtonMenuItem rbLapdvdrewriter;
javax.swing.JRadioButtonMenuItem rbLapgraphicscard;
javax.swing.JRadioButtonMenuItem rbLapharddisk;
javax.swing.JRadioButtonMenuItem rbLapheatsink;
javax.swing.JRadioButtonMenuItem rbLapkeyboard;
javax.swing.JRadioButtonMenuItem rbLapmotherboard;
javax.swing.JRadioButtonMenuItem rbLapscreen;
javax.swing.JRadioButtonMenuItem rbLapsoundcard;
// End of variables declaration
}