JDialog
Hey all,
I want to not only have the button event handler display the next but i also want to keep a running total of the buttons pressed. For some reason java does not like int total=total +25; It will not let me do that. When i create a new variable say total1 it says i havent initialized it. Can someone help me here?
/*
* CoinDeposit.java
*
* Created on June 1, 2007, 2:23 PM
*/
/**
*
* @author pberardi
*/
import javax.swing.JOptionPane;
publicclass CoinDepositextends javax.swing.JDialog{
/** Creates new form CoinDeposit */
public CoinDeposit(java.awt.Frame parent,boolean modal){
super(parent, modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
privatevoid initComponents(){
fiveCentButton =new javax.swing.JButton();
tenCentButton =new javax.swing.JButton();
twentyfiveCentButton =new javax.swing.JButton();
display =new javax.swing.JLabel();
total =new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
fiveCentButton.setText("deposit 5 cents");
fiveCentButton.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
fiveCentButtonActionPerformed(evt);
}
});
tenCentButton.setText("deposit 10 cents");
tenCentButton.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
tenCentButtonActionPerformed(evt);
}
});
twentyfiveCentButton.setText("deposit 25 cents");
twentyfiveCentButton.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
twentyfiveCentButtonActionPerformed(evt);
}
});
display.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
display.setText(" ");
display.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout layout =new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(132, 132, 132)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,false)
.addComponent(twentyfiveCentButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tenCentButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(fiveCentButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(138, 138, 138)
.addComponent(display))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(total)))
.addContainerGap(157, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(fiveCentButton)
.addGap(21, 21, 21)
.addComponent(tenCentButton)
.addGap(28, 28, 28)
.addComponent(twentyfiveCentButton)
.addGap(39, 39, 39)
.addComponent(display)
.addGap(32, 32, 32)
.addComponent(total)
.addContainerGap(64, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
privatevoid twentyfiveCentButtonActionPerformed(java.awt.event.ActionEvent evt){
[b] total.setText ("Your total is");[/b]
display.setText("You just deposited twenty-five cents");// TODO add your handling code here:
}
privatevoid tenCentButtonActionPerformed(java.awt.event.ActionEvent evt){
total.setText ("Your total is");
display.setText("You just deposited ten cents");// TODO add your handling code here:
}
privatevoid fiveCentButtonActionPerformed(java.awt.event.ActionEvent evt){
total.setText ("Your total is");
display.setText("You just deposited five cents");// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable(){
publicvoid run(){
new CoinDeposit(new javax.swing.JFrame(),true).setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel display;
private javax.swing.JButton fiveCentButton;
private javax.swing.JButton tenCentButton;
private javax.swing.JLabel total;
private javax.swing.JButton twentyfiveCentButton;
// End of variables declaration
}

