我正在与Netbeans开发收银机计划。当我在Eclipse中使用它时,它运行良好。但是,在我使用Netbeans更改了一些GUI后,这些功能无法正常工作。 (付款,取消) 当我点击New Order按钮时,我不知道为什么会出现问题。 我的代码出了什么问题?请!
package point.of.sales;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
void initializeBill()
{
nTotal = 0;
txtBill.setText(spaces(35) + "- Order -" );
btnTomatoBasilLinguine.setEnabled(true);
btnLinguineCarbonara.setEnabled(true);
btnShrimpPasta.setEnabled(true);
btnGrilledSalmonSalad.setEnabled(true);
btnCapreseSalad.setEnabled(true);
btnCoke.setEnabled(true);
btnGingerale.setEnabled(true);
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel5 = new javax.swing.JPanel();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel7 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
btnCheeseSalad = new javax.swing.JButton();
btnGrilledSalmonSalad = new javax.swing.JButton();
btnCapreseSalad = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
btnNewOrder = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
btnPayment = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtBill = new javax.swing.JTextArea();
jTextField1 = new javax.swing.JTextField();
jPanel8 = new javax.swing.JPanel();
btnShrimpPasta = new javax.swing.JButton();
btnTomatoBasilLinguine = new javax.swing.JButton();
btnLinguineCarbonara = new javax.swing.JButton();
jPanel9 = new javax.swing.JPanel();
btnBeer = new javax.swing.JButton();
btnCoke = new javax.swing.JButton();
btnGingerale = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
btnGrilledSalmonSalad.setText("Grilled Salmon Salad");
btnGrilledSalmonSalad.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGrilledSalmonSaladActionPerformed(evt);
}
});
btnCapreseSalad.setText("Caprese Salad");
btnCapreseSalad.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCapreseSaladActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnCheeseSalad, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnGrilledSalmonSalad, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnCapreseSalad, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnGrilledSalmonSalad, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCapreseSalad, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCheeseSalad, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(40, Short.MAX_VALUE))
);
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
btnNewOrder.setText("New Order");
btnNewOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNewOrderActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnPayment.setText("Payment");
txtBill.setColumns(20);
txtBill.setRows(5);
jScrollPane1.setViewportView(txtBill);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnNewOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnNewOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField1.setText("Tasting Room");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPanel8.setBorder(javax.swing.BorderFactory.createEtchedBorder());
btnShrimpPasta.setText("Shrimp Pasta");
btnShrimpPasta.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnShrimpPastaActionPerformed(evt);
}
});
btnTomatoBasilLinguine.setText("Tomato Basil Linguine");
btnTomatoBasilLinguine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTomatoBasilLinguineActionPerformed(evt);
}
});
btnLinguineCarbonara.setText("Linguine Carbonara");
btnLinguineCarbonara.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLinguineCarbonaraActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
jPanel8.setLayout(jPanel8Layout);
jPanel8Layout.setHorizontalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnShrimpPasta, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnTomatoBasilLinguine, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnLinguineCarbonara, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel8Layout.setVerticalGroup(
jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel8Layout.createSequentialGroup()
.addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnTomatoBasilLinguine, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnLinguineCarbonara, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnShrimpPasta, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(40, Short.MAX_VALUE))
);
jPanel9.setBorder(javax.swing.BorderFactory.createEtchedBorder());
btnBeer.setText("Beer");
btnBeer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBeerActionPerformed(evt);
}
});
btnCoke.setText("Coke ");
btnCoke.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCokeActionPerformed(evt);
}
});
btnGingerale.setText("Ginger Ale");
btnGingerale.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGingeraleActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
jPanel9.setLayout(jPanel9Layout);
jPanel9Layout.setHorizontalGroup(
jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel9Layout.createSequentialGroup()
.addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnBeer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCoke, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnGingerale, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel9Layout.setVerticalGroup(
jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel9Layout.createSequentialGroup()
.addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCoke, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnGingerale, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBeer, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(40, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, Short.MAX_VALUE)
.addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 351, Short.MAX_VALUE)
.addComponent(jPanel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 351, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(153, 153, 153)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 461, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel7Layout.createSequentialGroup()
.addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
jTabbedPane1.addTab("Cash Register", jPanel7);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void addItem(String food, double price)
{
txtBill.setText(txtBill.getText()+"\n"+" "+food+PRICE_FORMAT.format(price)+"\n");
nPreviousPrice = price;
nTotal +=price;
}
String spaces(int num)
{
String str="";
for(int i=0; i<num; i++)
str+=" ";
return str;
}
double getAmout()
{
try {
String strAnswer = JOptionPane.showInputDialog(null,
"Please enter the amout paid: ",
"Amout Paid", JOptionPane.OK_CANCEL_OPTION);
return Double.parseDouble(strAnswer);}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Please enter a number.",
"Number Format Exception", JOptionPane.OK_OPTION);
return -1;
}
catch (NullPointerException e)
{
System.out.println("Transaction Canceled");
return -2;
}
}
double getAmount()
{
try {
String strAnswer = JOptionPane.showInputDialog(null,
"Please enter the amount paid: ",
"Amount Paid", JOptionPane.OK_CANCEL_OPTION);
return Double.parseDouble(strAnswer);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Please enter a number.",
"Number Format Exception", JOptionPane.OK_OPTION);
return -1;
}
catch (NullPointerException e)
{
System.out.println("Transaction Canceled");
return -2;
}
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnTomatoBasilLinguineActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Tomato Basil Linguine" + spaces(19),13);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);// TODO add your handling code here:
}
private void btnCokeActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Coke" + spaces(52), 2);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint(); // TODO add your handling code here:
}
private void btnCapreseSaladActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Caprese Salad" + spaces(33), 5);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint(); // TODO add your handling code here:
}
private void btnGingeraleActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Gingerale" + spaces(44), 2);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint(); // TODO add your handling code here:
}
private void btnBeerActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Beer" + spaces(53),3);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint();// TODO add your handling code here:
}
private void btnNewOrderActionPerformed(java.awt.event.ActionEvent evt) {
initializeBill();
repaint();// TODO add your handling code here:
}
private void btnLinguineCarbonaraActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Linguine Carbonara" + spaces(24),15);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint(); // TODO add your handling code here:
}
private void btnShrimpPastaActionPerformed(java.awt.event.ActionEvent evt) {
addItem("Shrimp Pasta" + spaces(35),14);
btnPayment.setEnabled(true);
btnCancel.setEnabled(true);
repaint();// TODO add your handling code here:
}
private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt){
nSubTotal = nTotal;
txtBill.setText(txtBill.getText() + "\n" +
" " + "Total: " + spaces(41) + PRICE_FORMAT.format(nTotal) + "\n");
btnPayment.setEnabled(false);
btnCancel.setEnabled(false);
btnTomatoBasilLinguine.setEnabled(false);
btnLinguineCarbonara.setEnabled(false);
btnShrimpPasta.setEnabled(false);
btnCoke.setEnabled(false);
btnGingerale.setEnabled(false);
// get amount paid by client
double nAnswer = getAmount();
// if the cancel button is pressed, reinitialize.
if (nAnswer == DIALOG_CANCEL)
initializeBill();
else
{
// while the client gives an insufficent amount, ask again
while (nAnswer < nSubTotal)
{
if (nAnswer != DIALOG_NOT_NUM)
JOptionPane.showMessageDialog(null,
"The amount paid must be at least " +
PRICE_FORMAT.format(nSubTotal),
"Insufficent Amount", JOptionPane.OK_OPTION);
nAnswer = getAmount();
if (nAnswer == DIALOG_CANCEL)
{
initializeBill();
return;
}
}
txtBill.setText(txtBill.getText() + "\n" +
" " + "Paid: " + spaces(42) +
PRICE_FORMAT.format(nAnswer));
txtBill.setText(txtBill.getText() + "\n" +
" " + "Returned: " + spaces(33) +
PRICE_FORMAT.format(nAnswer-nSubTotal));
}
repaint();
}
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt){
txtBill.setText(txtBill.getText() + "\n" +
" " + strPreviousDrink +
spaces(40 - strPreviousDrink.length()) + "-" +
PRICE_FORMAT.format(nPreviousPrice) + "\n" + " (Canceled)\n");
nTotal -= nPreviousPrice;
btnCancel.setEnabled(false);
repaint();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private final DecimalFormat PRICE_FORMAT = new DecimalFormat("$###.##");
// flag, if the user does not enter a number in the dialog
private final int DIALOG_NOT_NUM = -1;
// flag, if the user cancels the dialog
private final int DIALOG_CANCEL = -2;
private double nTotal = 0, nSubTotal = 0, nPreviousPrice = 0;
private String strPreviousDrink;
// Variables declaration - do not modify
private javax.swing.JButton btnBeer, btnCancel, btnCapreseSalad, btnCheeseSalad, btnCoke, btnGingerale, btnGrilledSalmonSalad, btnLinguineCarbonara, btnNewOrder, btnPayment, btnShrimpPasta, btnTomatoBasilLinguine;
private javax.swing.JPanel jPanel1, jPanel2, jPanel5, jPanel7, jPanel8, jPanel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextArea txtBill;
}
答案 0 :(得分:3)
但是,在我使用Netbeans更改了一些GUI后,这些功能无效。 (付款,取消
您必须向ActionListener
添加JButton
实施,以便相应地处理相应的操作。您的btnCancel
和btnPayment
似乎都缺少此功能。例如:
btnCancel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
btnCancelActionPerformed(e);
}
});
如果您正在使用GUI构建器,我建议不要使用它:代码可能难以阅读,容易破解,如果/什么时候确实破坏而不知道代码构造方式/原因的基础知识会使错误变得非常困难诊断。