Prg421 Week 2 Ia

Only available on StudyMode
  • Topic: Void type
  • Pages : 6 (565 words )
  • Download(s) : 85
  • Published : May 1, 2013
Open Document
Text Preview
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

/**
* PRG 421 Week 2
* Retail Calculator Application
* Greg W. Stuart
*/
public class RetailCalculator extends JFrame implements ActionListener {

//instance variables for GUI elements
private JPanel jPanel1, jPanel2, jPanel3;
private JLabel lbTitle, lbItemName, lbDepartment, lbOriginalPrice, lbDiscountRate, lbSalePrice; private JTextField tfItemName, tfOriginalPrice, tfDiscountRate; private JButton btCalculate, btExit, btReset;

private JScrollPane jScrollPane;
private JTextArea jTextArea;
private JComboBox jComboBox;
private String strResult;
private NumberFormat numberFormat;

//constructor
public RetailCalculator {

super("Retail Calculator");
setLayout(null);
setSize(415, 440);
setLocation(150, 100);

//panels
jPanel1 = new JPanel();
jPanel1.setBounds(0, 0, 300, 30);
jPanel1.setLayout(new FlowLayout());

jPanel2 = new JPanel();
jPanel2.setBounds(0, 31, 300, 120);
jPanel2.setLayout(new GridLayout(6, 2));

jPanel3 = new JPanel();
jPanel3.setBounds(0, 151, 400, 250);
jPanel3.setLayout(new GridLayout(1, 1));

//title for pane
lbTitle = new JLabel("Retail Calculator");

//label and textfield for employee name
lbItemName = new JLabel("Item name: ");
lbItemName.setHorizontalAlignment(SwingConstants.RIGHT); tfItemName = new JTextField();

//label and textfield for hours worked
lbOriginalPrice = new JLabel("Original price: ");
lbOriginalPrice.setHorizontalAlignment(SwingConstants.RIGHT); tfOriginalPrice = new JTextField();

//label and textfield for hourly rate
lbDiscountRate = new JLabel("Discount rate: ");
lbDiscountRate.setHorizontalAlignment(SwingConstants.RIGHT); tfDiscountRate = new JTextField();

//label and textfield for hourly rate
lbSalePrice = new JLabel("");
lbSalePrice.setHorizontalAlignment(SwingConstants.RIGHT);

//add components to pane
jPanel1.add(lbTitle);

//panel 2
jPanel2.add(lbItemName);
jPanel2.add(tfItemName);
jPanel2.add(lbOriginalPrice);
jPanel2.add(tfOriginalPrice);
jPanel2.add(lbDiscountRate);
jPanel2.add(tfDiscountRate);

//departments combo box
lbDepartment = new JLabel("Department: ");
lbDepartment.setHorizontalAlignment(SwingConstants.RIGHT); jComboBox = new JComboBox();
jComboBox.addItem("Select");
jComboBox.addItem("Men's Clothing");
jComboBox.addItem("Women's Clothing");
jComboBox.addItem("House wares");
jComboBox.addItem("Stationary");
jComboBox.addItem("Under garments");

jPanel2.add(lbDepartment);
jPanel2.add(jComboBox);

//buttons
btCalculate = new JButton("Calculate");
btCalculate.addActionListener(this);
btExit = new JButton("Exit");
btExit.addActionListener(this);
btReset = new JButton("Reset");
btReset.addActionListener(this);

jPanel2.add(btCalculate);
jPanel2.add(btExit);
jPanel2.add(lbSalePrice);
jPanel2.add(btReset);

//scroll pane and text area
jTextArea = new JTextArea();
jScrollPane = new JScrollPane(jTextArea);...
tracking img