Wednesday, July 17, 2019
Retail Calculator
portion retail. calculator consequence java. awt. * import java. awt. event. * import java. text. DecimalFormat import javax. swing. * usual class retailCalculator extends JFrame // piddle ojects JLabel section JLabel number JLabel pay heed JLabel expenditure JLabel dissolve JLabel barter JComboBox dept JTextField full stopNum JTextField incidentName JTextField itemPrice JTextField itemDisc JTextField sales eventPrice JButton calculate JButton take a leak macrocosm RetailCalculator() //set object variables super(Retail Sales Calculator) //windowpane denomination setSize(250, 250) //set window size etDefaultCloseOperation(JFrame. EXIT_ON_CLOSE) //window close GridLayout grid = unseasoned GridLayout(7, 2) setLayout(grid) department = freshly JLabel(Department) dept = wise JComboBox() dept. carry occurrence( involve) dept. addItem(Apperal) dept. addItem(Automotive) dept. addItem(Cosmetics) dept. addItem(Jewlry) dept. addItem(Pets) dept. addItem(Pharmacy) //add ItemLi stener combobox and jtextfield dept. addItemListener(new ItemListener() public vacuity itemStateChanged(ItemEvent ie) soak up str = (String)dept. getSelectedItem() itemNum. setText(str) //end public reverse ) //end item attender number = new JLabel(Item summate) itemNum = new JTextField(10) name = new JLabel(Item Name) itemName = new JTextField(10) price = new JLabel(Original Price) itemPrice = new JTextField(10) discount = new JLabel(Discount) itemDisc = new JTextField(10) sale = new JLabel(Sale Price) salePrice = new JTextField(10) salePrice. setEditable(false) calculate = new JButton(Calculate) illuminate = new JButton(Clear) //add objects to JFrame add(department) add(dept) add(number) add(itemNum) add(name) add(itemName) dd(price) add(itemPrice) add(discount) add(itemDisc) add(sale) add(salePrice) add(calculate) add( piss) //add event listener to calculate sale price calculate. addActionListener(new ActionListener() public void actionPerformed(ActionEvent retail) Stri ng input1 String input2 pronged origPrice double percOff double clearance input1 = itemPrice. getText() input2 = itemDisc. getText() origPrice = Double. parseDouble(input1) percOff = Double. parseDouble(input2)/100 clearance = origPrice (origPrice * percOff) DecimalFormat df = new DecimalFormat($,. ) salePrice. setText(df. clearance) //output to jtextfield ) //clear feilds clear. addActionListener (new ActionListener() public void actionPerformed(ActionEvent event) //JButton event dept. setSelectedIndex(0) //clear itemNum. setText(null) //clear item number itemName. setText(null) //clear item name itemPrice. setText(null) //clear item name itemDisc. setText(null) //clear item name salePrice. setText(null) //clear item name ) setVisible(true) public static void main(String args) RetailCalculator rc = new RetailCalculator()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.