I designed to look like that picture click here:
http://i195.photobucket.com/albums/z285/boiishuvo/eg.jpg
But I got two errors shown below:
Pizza.java:150: cannot find symbol
symbol : constructor Labels(java.lang.String)
location: class Labels
localJPanel5.add("North", new Labels("PIZZA"));
^
Pizza.java:187: cannot find symbol
symbol : constructor Labels(java.lang.String)
location: class Labels
localJPanel12.add(new Labels("PRICE"));
^
Can anyone fix that or any suggestions?
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
//import javax.swing.ButtonGroup;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class Pizza extends JApplet {
String[] pizza;
JList pizzaList;
JButton clearOrderButton;
JButton orderButton;
JTextField priceTextField;
JTextField countTextField;
JTextArea pizzaCountText;
JTextField totalTextField;
int indexPizza;
double onePizzaPrice;
double totalPrice;
boolean pizzaReady;
public Pizza() {
this.pizza = new String[] { "Supremo Supreme", "Supreme", "Chicken", "Aussie", "Vegie", "Hawaiian" };
this.pizzaList = new JList(this.pizza);
this.clearOrderButton = new JButton("Clear Order");
this.orderButton = new JButton("Order");
this.priceTextField = new JTextField("0.0");
this.countTextField = new JTextField();
this.pizzaCountText = new JTextArea("Pizza Ordered: 0");
this.totalTextField = new JTextField();
this.indexPizza = -1;
this.onePizzaPrice = 0.0D;
this.totalPrice = 0.0D;
this.pizzaReady = false;
}
public void updatePrice() {
if (this.indexPizza == 0)
this.onePizzaPrice = 13.949999999999999D;
else if (this.indexPizza == 1)
this.onePizzaPrice = 12.949999999999999D;
else if ((this.indexPizza == 2) || (this.indexPizza == 3))
this.onePizzaPrice = 12.50D;
else if (this.indexPizza == 4)
this.onePizzaPrice = 10.949999999999999D;
else if (this.indexPizza == 5)
this.onePizzaPrice = 10.50D;
else {
this.onePizzaPrice = 0.0D;
}
this.totalPrice = (this.onePizzaPrice);
if ((this.totalPrice <= 26.0D)) {
this.totalPrice += 5.0D;
}
this.onePizzaPrice = (Math.rint(this.onePizzaPrice * 100.0D) / 100.0D);
this.totalPrice = (Math.rint(this.totalPrice * 100.0D) / 100.0D);
this.priceTextField.setText(Double.toString(this.onePizzaPrice));
if ((this.pizzaReady))
this.totalTextField.setText(Double.toString(this.totalPrice));
else
this.totalTextField.setText("");
}
public void paint(Graphics paramGraphics) {
super.paint(paramGraphics);
paramGraphics.setFont(new Font("MonoSpaced", 1, 25));
paramGraphics.drawString("ONLINE PIZZA ORDER", 0, 30);
Image localImage = getImage(getDocumentBase(), "pizza.jpg");
paramGraphics.drawImage(localImage, 0, 440, 280, 200, this);
}
public void init() {
Container localContainer = getContentPane();
localContainer.setBackground(Color.WHITE);
getGraphics().drawString("ONLINE PIZZA ORDER", 0, 30);
localContainer.setLayout(new FlowLayout(0, 0, 40));
JPanel localJPanel1 = new JPanel();
localJPanel1.setLayout(new FlowLayout(0, 0, 10));
localJPanel1.setBackground(Color.WHITE);
localJPanel1.setPreferredSize(new Dimension(365, 385));
JPanel localJPanel2 = new JPanel();
localJPanel2.setBackground(Color.WHITE);
localJPanel2.setLayout(new BorderLayout(0, 0));
localJPanel2.setPreferredSize(new Dimension(365, 220));
JPanel localJPanel3 = new JPanel();
localJPanel3.setBackground(Color.WHITE);
localJPanel3.setLayout(new BorderLayout(0, 5));
localJPanel3.setPreferredSize(new Dimension(365, 100));
JPanel localJPanel4 = new JPanel();
localJPanel4.setBackground(Color.WHITE);
localJPanel4.setLayout(new BorderLayout(0, 10));
localJPanel4.setPreferredSize(new Dimension(365, 26));
JPanel localJPanel5 = new JPanel();
localJPanel5.setBackground(Color.WHITE);
localJPanel5.setLayout(new BorderLayout(0, 5));
JPanel localJPanel6 = new JPanel();
localJPanel6.setBackground(Color.WHITE);
localJPanel6.setLayout(new BorderLayout(5, 0));
JPanel localJPanel7 = new JPanel();
localJPanel7.setPreferredSize(new Dimension(115, 120));
localJPanel7.setBackground(Color.WHITE);
this.pizzaList.setSelectionMode(1);
this.pizzaList.addListSelectionListener(new Pizza.Listeners().PizzaListListener);
JScrollPane localJScrollPane1 = new JScrollPane(this.pizzaList);
localJScrollPane1.setPreferredSize(new Dimension(115, 116));
localJPanel7.add(localJScrollPane1);
localJPanel6.add("West", localJPanel7);
localJPanel5.add("North", new Labels("PIZZA"));
localJPanel5.add("South", localJPanel6);
JPanel localJPanel12 = new JPanel();
localJPanel12.setBackground(Color.WHITE);
localJPanel12.setLayout(new FlowLayout(0, 0, 10));
localJPanel12.setPreferredSize(new Dimension(245, 87));
JPanel localJPanel13 = new JPanel();
localJPanel13.setBackground(Color.WHITE);
localJPanel13.setLayout(new BorderLayout(10, 0));
localJPanel13.setPreferredSize(new Dimension(300, 30));
JPanel localJPanel14 = new JPanel();
localJPanel14.setPreferredSize(new Dimension(115, 20));
localJPanel14.setBackground(Color.WHITE);
localJPanel14.setLayout(new FlowLayout(2, 0, 0));
this.priceTextField.setPreferredSize(new Dimension(50, 30));
this.priceTextField.setEditable(false);
this.priceTextField.setBackground(Color.WHITE);
localJPanel14.add(new JTextArea("$"));
localJPanel14.add(this.priceTextField);
localJPanel13.add("West", localJPanel14);
JPanel localJPanel15 = new JPanel();
localJPanel15.setBackground(Color.WHITE);
localJPanel15.setLayout(new FlowLayout(0, 0, 0));
localJPanel15.setPreferredSize(new Dimension(120, 20));
this.countTextField.setPreferredSize(new Dimension(50, 30));
localJPanel15.add(this.countTextField);
localJPanel13.add("Center", localJPanel15);
localJPanel12.add(new Labels("PRICE"));
localJPanel12.add(localJPanel13);
JPanel localJPanel16 = new JPanel();
localJPanel16.setBackground(Color.WHITE);
localJPanel16.setLayout(new BorderLayout(0, 0));
localJPanel16.setPreferredSize(new Dimension(365, 55));
JPanel localJPanel17 = new JPanel();
localJPanel17.setBackground(Color.WHITE);
localJPanel17.setPreferredSize(new Dimension(245, 55));
JTextArea localJTextArea1 = new JTextArea("*extra $1.50 for Pan\n*extra $1.10 for each topping\n*delivery fee $5.00 waived for over $26 orders", 3, 1);
localJTextArea1.setBackground(Color.CYAN);
localJTextArea1.setEditable(false);
localJPanel17.add("West", localJTextArea1);
JPanel localJPanel18 = new JPanel();
localJPanel18.setBackground(Color.WHITE);
localJPanel18.setLayout(new FlowLayout(1, 0, 17));
localJPanel18.setPreferredSize(new Dimension(80, 25));
localJPanel16.add("West", localJPanel17);
localJPanel16.add("East", localJPanel18);
JPanel localJPanel19 = new JPanel();
localJPanel19.setBackground(Color.WHITE);
localJPanel19.setLayout(new BorderLayout(0, 0));
localJPanel19.setPreferredSize(new Dimension(365, 40));
JPanel localJPanel20 = new JPanel();
localJPanel20.setBackground(Color.GREEN);
localJPanel20.setLayout(new FlowLayout(1, 0, 10));
localJPanel20.setPreferredSize(new Dimension(110, 50));
JPanel localJPanel21 = new JPanel();
localJPanel21.setBackground(Color.WHITE);
localJPanel21.setLayout(new FlowLayout(1, 5, 5));
localJPanel21.setPreferredSize(new Dimension(155, 25));
this.pizzaCountText.setBackground(Color.GREEN);
this.pizzaCountText.setEditable(false);
this.pizzaCountText.setPreferredSize(new Dimension(110, 20));
localJPanel20.add("West", this.pizzaCountText);
this.totalTextField.setPreferredSize(new Dimension(100, 25));
JTextArea localJTextArea3 = new JTextArea("TOTAL");
localJTextArea3.setEditable(false);
localJPanel21.add("West", localJTextArea3);
localJPanel21.add("East", this.totalTextField);
localJPanel19.add("West", localJPanel20);
localJPanel19.add("East", localJPanel21);
JPanel localJPanel22 = new JPanel();
localJPanel22.setLayout(new BorderLayout(0, 0));
localJPanel22.setPreferredSize(new Dimension(360, 30));
JPanel localJPanel23 = new JPanel();
localJPanel23.setLayout(new FlowLayout(1, 0, 0));
localJPanel23.setBackground(Color.WHITE);
localJPanel23.setPreferredSize(new Dimension(98, 26));
JPanel localJPanel24 = new JPanel();
localJPanel24.setLayout(new FlowLayout(1, 20, 0));
localJPanel24.setBackground(Color.WHITE);
localJPanel23.setPreferredSize(new Dimension(98, 26));
this.clearOrderButton.addActionListener(new Pizza.Listeners().ClearButtonListener);
localJPanel23.add(this.clearOrderButton);
this.orderButton.addActionListener(new Pizza.Listeners().OrderButtonListener);
localJPanel24.add(this.orderButton);
localJPanel22.add("Center", localJPanel23);
localJPanel22.add("East", localJPanel24);
localJPanel2.add("Center", localJPanel12);
localJPanel3.add("North", localJPanel16);
localJPanel3.add("South", localJPanel19);
localJPanel4.add("North", localJPanel22);
localJPanel1.add("North", localJPanel2);
localJPanel1.add("Center", localJPanel3);
localJPanel1.add("North", localJPanel4);
localContainer.add(localJPanel1);
localContainer.setVisible(true);
}
class Listeners {
ActionListener ClearButtonListener = new ActionListener() {
public void actionPerformed(ActionEvent paramActionEvent) {
Pizza.this.pizzaList.clearSelection();
Pizza.this.countTextField.setText("");
Pizza.this.pizzaReady = false;
Pizza.this.pizzaCountText.setText("Pizza Ordered: 0");
Pizza.this.orderButton.setEnabled(true);
}
};
ActionListener OrderButtonListener = new ActionListener() {
public void actionPerformed(ActionEvent paramActionEvent) {
Pizza.this.pizzaReady = (!Pizza.this.pizzaList.isSelectionEmpty());
String str;
if (Pizza.this.pizzaReady) {
str = "\n\nOrdered\n";
str = str + "Pizza: " + Pizza.this.pizza[Pizza.this.indexPizza] + "\n";
str = str + "\n\nTotal: " + Pizza.this.totalPrice + "\n";
JOptionPane.showMessageDialog(null, "Pizza Purchased" + str, "Results", 2);
Pizza.this.pizzaCountText.setText("Pizza Ordered: ");
Pizza.this.orderButton.setEnabled(false);
}
else {
str = "\n\nReason:\n";
if (!Pizza.this.pizzaReady)
str = str + " - Pizza Not Selected\n";
JOptionPane.showMessageDialog(null, "Pizza Not Purchased" + str, "Results", 0);
}
}
};
ListSelectionListener PizzaListListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent paramListSelectionEvent) {
JList localJList = (JList)paramListSelectionEvent.getSource();
if (!localJList.isSelectionEmpty())
Pizza.this.indexPizza = localJList.getSelectedIndex();
else
Pizza.this.indexPizza = -1;
Pizza.this.pizzaReady = (!localJList.isSelectionEmpty());
Pizza.this.updatePrice();
}
};
Listeners()
{
}
}
}