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()
    {
    }
  }
}

Where is Labels defined?

Where is Labels defined?

ok here is the labels code

import java.awt.*;
import javax.swing.*;

class Labels extends JPanel {
    Labels(String String1, String String2, String String3) {
        setBackground(Color.WHITE);
        setLayout(new BorderLayout(10, 0));
        
        JPanel menuTxt1 = new JPanel();
        menuTxt1.setBackground(Color.BLUE);
        menuTxt1.setLayout(new FlowLayout(1, 0, 0));
        menuTxt1.setPreferredSize(new Dimension(115, 18));
        JLabel menuLab1 = new JLabel(String1);
        menuLab1.setBackground(Color.BLUE);
        menuLab1.setOpaque(true);
        menuTxt1.add(menuLab1);
        
        /*JPanel menuTxt2 = new JPanel();
        menuTxt2.setBackground(Color.BLUE);
        menuTxt2.setLayout(new FlowLayout(1, 0, 0));
        menuTxt2.setPreferredSize(new Dimension(120, 18));
        JLabel menuLab2 = new JLabel(String2);
        menuLab2.setBackground(Color.BLUE);
        menuLab2.setOpaque(true);
        menuTxt2.add(menuLab2);
        
        JPanel menuTxt3 = new JPanel();
        menuTxt3.setBackground(Color.YELLOW);
        menuTxt3.setLayout(new FlowLayout(1, 0, 0));
        menuTxt3.setPreferredSize(new Dimension(110, 18));
        JLabel menuLab3 = new JLabel(String3);
        menuLab3.setBackground(Color.YELLOW);
        menuLab3.setOpaque(true);
        menuTxt3.add(menuLab3);*/
        
        add("West", menuTxt1);
        /*add("Center", menuTxt2);
        add("East", menuTxt3);*/
    }

Labels(String String1, String String2) {
    setBackground(Color.WHITE);
    setLayout(new BorderLayout(5, 0));

    JPanel menuTxt1 = new JPanel();
    menuTxt1.setBackground(Color.PINK);
    menuTxt1.setLayout(new FlowLayout(1, 0, 0));
    menuTxt1.setPreferredSize(new Dimension(115, 18));
    JLabel menuLab1 = new JLabel(String1);
    menuLab1.setBackground(Color.PINK);
    menuLab1.setOpaque(true);
    menuTxt1.add(menuLab1);

    JPanel menuTxt2 = new JPanel();
    menuTxt2.setBackground(Color.YELLOW);
    menuTxt2.setLayout(new FlowLayout(1, 0, 0));
    menuTxt2.setPreferredSize(new Dimension(120, 18));
    JLabel menuLab2 = new JLabel(String2);
    menuLab2.setBackground(Color.YELLOW);
    menuLab2.setOpaque(true);
    menuTxt2.add(menuLab2);

    add("West", menuTxt1);
    add("East", menuTxt2);
  }
}

Your constructor has 2 arguments, you only enter 1.

Your constructor has 2 arguments, you only enter 1.

Oh right. I got you. But I have one problem (I didn't make these codes, I got them off some websites).

import java.awt.*;
import javax.swing.*;

class Labels extends JPanel {
    Labels(String String1, String String2, String String3) {
        setBackground(Color.WHITE);
        setLayout(new BorderLayout(10, 0));
        
        JPanel menuTxt1 = new JPanel();
        menuTxt1.setBackground(Color.BLUE);
        menuTxt1.setLayout(new FlowLayout(1, 0, 0));
        menuTxt1.setPreferredSize(new Dimension(115, 18));
        JLabel menuLab1 = new JLabel(String1);
        menuLab1.setBackground(Color.BLUE);
        menuLab1.setOpaque(true);
        menuTxt1.add(menuLab1);
        
        add("Center", menuTxt1);
    }

Labels(String String1) {
    setBackground(Color.WHITE);
    setLayout(new BorderLayout(5, 0));

    JPanel menuTxt1 = new JPanel();
    menuTxt1.setBackground(Color.PINK);
    menuTxt1.setLayout(new FlowLayout(1, 0, 0));
    menuTxt1.setPreferredSize(new Dimension(115, 18));
    JLabel menuLab1 = new JLabel(String1);
    menuLab1.setBackground(Color.PINK);
    menuLab1.setOpaque(true);
    menuTxt1.add(menuLab1);

    add("West", menuTxt1);
  }
}

That code works properly. But I don't need three strings

Labels(String String1, String String2, String String3)

So I removed two strings and it ran not working. The error says

Labels.java:43: Labels(java.lang.String) is already defined in Labels
Labels(String String2) {
^

Any suggestions?

I suggest you read up on constructors. You cannot have 2 constructors with the exact same arguments. Quickest fix for you is to remove one of the constructors entirely.

Never mind. I found the solution.

I have two more problems.

Since I added the image code

Image localImage = getImage(getDocumentBase(), "pizza.jpg");
paramGraphics.drawImage(localImage, 0, 440, 280, 200, this);

It didn't appear on the screen. Do I need to add something in the HTML? My HTML code is here

<html>
<body>
<applet code = "Pizza.class" width = "400" height = "700">
</applet>
</body>
</html>

Another problem (that is the most important one): I already added the function of pizza list eg

public Pizza() {
    this.pizza = new String[] { "Supremo Supreme", "Supreme", "Chicken", "Aussie", "Vegie", "Hawaiian" };

and

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;
    }

But they didn't appear on the screen either. Any suggestions?

I solved the first problem so ignore it!

But the second problem is still present.

Where is the image file? Is it with the class file?

they didn't appear on the screen eithe

What screen? Please explain where you expect to see them.

If you got this from a website and it doesn't even work then there is probably something very wrong within the code. I will not debug the code. If you wrote this yourself you would of had less problems.

I solved all the problems :)

One more thing, how do I move the image from bottom to the top (below the title)?

Are you asking about the layout of components in your GUI?

Are you asking about the layout of components in your GUI?

Yes.

super.paint(paramGraphics);
Image localImage = getImage(getDocumentBase(), "pizza.jpg");
paramGraphics.setFont(new Font("Freestyle Script", 1, 45));
paramGraphics.drawString("Welcome to Pizza Online", 0, 30);
paramGraphics.drawImage(localImage, 0, 440, 280, 200, this);

How do I move the image to the top (just below the title)? Click here to see the screen http://i195.photobucket.com/albums/z285/boiishuvo/egscren.jpg

> How do I move the image to the top (just below the title)?

Change the drawImage() coordinates. Of course, then you will have to make some space for it at the top. So you would have to change your component layout.

> How do I move the image to the top (just below the title)?

Change the drawImage() coordinates. Of course, then you will have to make some space for it at the top. So you would have to change your component layout.

Sorry I don't get it. Something like that?

super.paint(paramGraphics);
    Image localImage = getImage(drawImage(), "pizza.jpg");
    paramGraphics.setFont(new Font("Freestyle Script", 1, 45));
    paramGraphics.drawString("Welcome to Pizza Online", 0, 30);
    paramGraphics.drawImage(localImage, 0, 440, 280, 200, this);

What do you mean by make some space?

Also how do I add a small image under the text

JTextArea localJTextArea1 = new JTextArea("Internet orders can be prepaid using\none of the above credit cards", 2, 1);
localJTextArea1.setBackground(Color.BLUE);
localJTextArea1.setEditable(false);
localJPanel17.add("West", localJTextArea1);

paramGraphics.drawImage(localImage, 0, 440, 280, 200, this); Read the API doc on the drawImage method. Those numbers are the coordinates and dimensions of the image being drawn. If you want it drawn elsewhere, you have to change them.

> What do you mean by make some space?

Well, I assume you don't want to draw right over your other components, so you have to make some space in your layout to accommodate the image. I would actually recommend placing the image in a JLabel so it can be placed in your layout as a component.

You can add the image under the text the same way. Here's a link on using JLabels to display images: http://download.oracle.com/javase/tutorial/uiswing/components/icon.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.