How to Create a Restaurant Menu With a Java Program Applet

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Create a Restaurant Menu With a Java Program Applet
You can have a menu on your own website. (Maria Toutoudaki/Photodisc/Getty Images)

Using the Java Applet feature, you can embed an automatic menu for your restaurant into it's web page. Among other features, this will allow you to separate dishes from the style of the applet, making trivial changes to the look of the applet or to the dishes within which will be updated instantly.

Skill level:


  1. 1

    Open your favourite text editor, or, if you prefer, a dedicated Java development environment such as Netbeans. Immediately save the file as ""

  2. 2

    Paste the following within ""

    package restaurantmenu;

    import java.awt.GridLayout;

    import java.awt.Image;

    import java.awt.Toolkit;

    import java.util.ArrayList;

    import javax.swing.JApplet;

    import java.awt.Panel;

    public class Main extends JApplet {

    ArrayList<Panel> dish List = new ArrayList<Panel>();
    public void init() {
        this.setLayout(new GridLayout(0, 1));

    // To load new dishes, simple repeat these two lines, as often as needed, for every dish.

        Image I = Toolkit.getDefaultToolkit().get Image("kungpao.jpg");
        dishList.add(new ItemPanel("Kung Pao Chicken", "Spicy Chicken Dish", "$9.95", i));

        Image I = Toolkit.getDefaultToolkit().get Image("orangechicken.jpg");
        dishList.add(new ItemPanel("Orange Chicken", "A tasty dish.","$10.25" ,i));
        for (Panel dish : dish List) {


    This creates a basic applet containing an array list of dishes. As soon as the applet is loaded, it creates two new dishes using the "ItemPanel" class that you will create in section two: Kung Pao Chicken and Orange Chicken and adds them to the menu.

  3. 3

    Save your work and close the document.

  1. 1

    Open another copy of your favourite text editor. Save the document as ""

  2. 2

    Paste the following into it:

    package restaurantmenu;

    import java.awt.BorderLayout;

    import java.awt.Dimension;

    import java.awt.Image;

    import javax.swing.ImageIcon;

    import javax.swing.JButton;

    import javax.swing.JLabel;

    import java.awt.Panel;

    public class ItemPanel extends Panel {

    JLabel name;
    JLabel description;
    JLabel price;
    JButton image;
    static final int IMAGE_WIDTH = 100;
    static final int IMAGE_HEIGHT = 100;
    public ItemPanel(String dish Name, String dish Description, String dishprice, Image picture) {
        image = new JButton(new ImageIcon(picture));
        name = new JLabel(dishName);
        price = new JLabel(dishprice);
        description = new JLabel(dishDescription);
        image.setPreferredSize(new Dimension(IMAGE_WIDTH, IMAGE_HEIGHT));
        this.setLayout(new BorderLayout());
        this.add(name, BorderLayout.NORTH);
        this.add(image, BorderLayout.WEST);
        this.add(description, BorderLayout.CENTER);
        this.add(price, BorderLayout.EAST);


    This holds information about the actual items on the menu and how they should be laid out. It takes a dish name, a dish description, a dish price, and a picture, in that order. You can see how this is called in step two of the Applet class.

  3. 3

    Save your work.

  4. 4

    Add the following code to your web page's HTML file:

    <APPLET code="Main.class" width=600 height=200></APPLET>

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.