/    Sign up×
Community /Pin to ProfileBookmark

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!

to post a comment
Java

0Be the first to comment 😎

×

Success!

Help @cottner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...