import java.text.NumberFormat;
import java.util.Locale;
import java.awt.event.ActionEvent; ///might not need
public class PizzaGUI extends javax.swing.JFrame {
/**
* Creates new form PizzaGUI
*/
public PizzaGUI() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
CalculateButton = new javax.swing.JButton();
ClearButton = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
TotalPrice = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
smallRadio = new javax.swing.JRadioButton();
medRadio = new javax.swing.JRadioButton();
largeRadio = new javax.swing.JRadioButton();
jPanel2 = new javax.swing.JPanel();
SausageTopping = new javax.swing.JCheckBox();
PepperoniTopping = new javax.swing.JCheckBox();
SalamiTopping = new javax.swing.JCheckBox();
OlivesTopping = new javax.swing.JCheckBox();
MushroomsTopping = new javax.swing.JCheckBox();
AnchoviesTopping = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Giovanni's Pizza");
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Giovanni's Online Pizza Order");
CalculateButton.setText("Calculate");
CalculateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CalculateButtonActionPerformed(evt);
}
});
ClearButton.setText("Clear");
ClearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ClearButtonActionPerformed(evt);
}
});
jLabel4.setText("Price:");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Size"));
jPanel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
buttonGroup1.add(smallRadio);
smallRadio.setText("Small");
smallRadio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
smallRadioActionPerformed(evt);
}
});
buttonGroup1.add(medRadio);
medRadio.setText("Medium");
buttonGroup1.add(largeRadio);
largeRadio.setText("Large");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(smallRadio)
.addGap(26, 26, 26)
.addComponent(medRadio)
.addGap(18, 18, 18)
.addComponent(largeRadio)
.addContainerGap(35, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(smallRadio)
.addComponent(medRadio)
.addComponent(largeRadio))
.addGap(72, 72, 72))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Toppings", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));
jPanel2.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
SausageTopping.setText("Sausage");
SausageTopping.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SausageToppingActionPerformed(evt);
}
});
PepperoniTopping.setText("Pepperoni");
SalamiTopping.setText("Salami");
OlivesTopping.setText("Olives");
MushroomsTopping.setText("Mushrooms");
AnchoviesTopping.setText("Anchovies");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(SausageTopping)
.addComponent(PepperoniTopping)
.addComponent(SalamiTopping))
.addGap(29, 29, 29)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(AnchoviesTopping)
.addComponent(MushroomsTopping)
.addComponent(OlivesTopping))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(SausageTopping)
.addComponent(OlivesTopping))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(PepperoniTopping)
.addComponent(MushroomsTopping))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(SalamiTopping)
.addComponent(AnchoviesTopping))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
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(64, 64, 64)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(CalculateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TotalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(21, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(CalculateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(TotalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(24, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void SausageToppingActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void smallRadioActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void CalculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
// declaring variables and create constants
NumberFormat currency = NumberFormat.getCurrencyInstance(); //formats
double SmallPizza, MediumPizza, LargePizza;
double Sausage, Salami, Mushrooms, Pepperoni, Olives, Anchovies;
SmallPizza = 6.99;
MediumPizza = 8.99;
LargePizza = 10.99;
Sausage = 1.49;
Salami = 1.49;
Pepperoni = 1.49;
Olives = 0.99;
Mushrooms = 0.99;
Anchovies = 0.99;
}
private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {
// clears everything. If radiobutton topping/ if price is selected, reset it.
smallRadio.setSelected(false);
medRadio.setSelected(false);
largeRadio.setSelected(false);
SausageTopping.setSelected(false);
SalamiTopping.setSelected(false);
PepperoniTopping.setSelected(false);
OlivesTopping.setSelected(false);
MushroomsTopping.setSelected(false);
AnchoviesTopping.setSelected(false);
TotalPrice.setText(null);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see [url]http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html[/url]
*/
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(PizzaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PizzaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PizzaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PizzaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PizzaGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JCheckBox AnchoviesTopping;
private javax.swing.JButton CalculateButton;
private javax.swing.JButton ClearButton;
private javax.swing.JCheckBox MushroomsTopping;
private javax.swing.JCheckBox OlivesTopping;
private javax.swing.JCheckBox PepperoniTopping;
private javax.swing.JCheckBox SalamiTopping;
private javax.swing.JCheckBox SausageTopping;
private javax.swing.JTextField TotalPrice;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton largeRadio;
private javax.swing.JRadioButton medRadio;
private javax.swing.JRadioButton smallRadio;
// End of variables declaration
}