I am creating a POS system and have the GUI complete, but now I am having a hard time figuring out how to get the item to display once the item code is input. Here is my code:
import javax.swing.JFrame;
import javax.swing.JButton;
import java.text.NumberFormat;
import java.awt.event.*;
public class PosGUI extends javax.swing.JFrame {
public PosGUI() {
initComponents();
}
@SuppressWarnings(“unchecked”)
private void initComponents() {
total = new javax.swing.JButton();
Enter = new javax.swing.JButton();
ItemCodeNumber = new javax.swing.JLabel();
ItemCode = new javax.swing.JTextField();
DisplayItemNamePrice = new javax.swing.JLabel();
SubTotal = new javax.swing.JLabel();
SalesTax = new javax.swing.JLabel();
TotalPurchase = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“Point of Sale”);
total.setText(“Total”);
total.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
totalActionPerformed(evt);
// I know that my action needs to be input here so when the Total button is pushed it knows what to do, but I do
//not know where to start. Help!///
}
});
Enter.setText(“Enter”);
ItemCode.setText(“Item Code”);
DisplayItemNamePrice.setText(“Item Name: Item Price:”);
SubTotal.setText(“Sub Total:”);
SalesTax.setText(“Sales Tax:”);
TotalPurchase.setText(“Total:”);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ItemCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
.addComponent(ItemCodeNumber)
.addGap(134, 134, 134))
.addGroup(layout.createSequentialGroup()
.addComponent(DisplayItemNamePrice)
.addContainerGap())))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(72, Short.MAX_VALUE)
.addComponent(total)
.addGap(47, 47, 47)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(SubTotal)
.addComponent(SalesTax)
.addComponent(TotalPurchase)
.addGroup(layout.createSequentialGroup()
.addGap(130, 130, 130)
.addComponent(Enter)))
.addGap(35, 35, 35))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ItemCodeNumber)
.addComponent(ItemCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addComponent(DisplayItemNamePrice)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(total)
.addComponent(Enter))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
.addComponent(SubTotal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(SalesTax)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TotalPurchase)
.addGap(23, 23, 23))
);
pack();
}// </editor-fold>
private void totalActionPerformed(java.awt.event.ActionEvent evt) {
// I know my action code goes here, but I am having a hard time understanding how to do that
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PosGUI().setVisible(true);
}
});
}
// Variables declaration
private javax.swing.JLabel DisplayItemNamePrice;
private javax.swing.JButton Enter;
private javax.swing.JTextField ItemCode;
private javax.swing.JLabel ItemCodeNumber;
private javax.swing.JLabel SalesTax;
private javax.swing.JLabel SubTotal;
private javax.swing.JLabel TotalPurchase;
private javax.swing.JButton total;
// End of variables declaration
}
Here are the items and item codes:
Item Code Item Name Item Price
105 Shoes $25.00
110 Doll $15.00
120 GPS System $100.00
160 Gift Basket $30.00
200 Vitamins $10.00
Please help!