Results 1 to 8 of 8
  1. #1
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Question Pizza Order System

    hey guyz , i did this program to order pizza , however icant get to see anything in applet window !! no text , no button , nothing !! whats wrong with my code ?

    Java Code:
    /* password authentication*/
     
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    
    
    public class Pizza extends Applet implements ActionListener,KeyListener  {
    	// Constants for storing Prices
    	private final int 
    			small = 5,
    			medium = 7,
    			large = 9,
    			extralarge=12,
    			cheese=0,
    			sausage=2,
    			mushroom=2,
    			pepper=2,
    			chicken=2;
    			
    			
    				   		 
    	// Size //
    	ButtonGroup sizeBGroup;
    	
    	JRadioButton smallJRadio,
    				 mediumJRadio,
    				 largeJRadio,
    				 extralargeJRadio;
    				 
    	// toppings//
    	
    	JCheckBox cheeseJCheck,
    			  sausageJCheck,
    			  mushroomJCheck,
    			  pepperJCheck,
    			  chickenJCheck;
    			  
    	// Labels//
    	
    	Label welcomeLabel,
    		  pizzasizeLabel,
    		  toppingLabel,
    		  priceLabel,
    		  pricedisplayLabel;
    		  
    	// TextFields//
    	
    	TextField priceText,
    			  pizzaText;
    	
    	// Buttons//
    	
    	Button resetButton,orderButton;
    	
    	
    	public void init() {
    	
    		setBackground(new Color(205,205,205));
    		setLayout(new BorderLayout(0,0));
    
    
    		// initilizing labels//
    		welcomeLabel=new Label("Welcome to Mrjojo Pizza Menu");
    		pizzasizeLabel=new Label("choose ur desired size");
    		toppingLabel=new Label("choose ur desired topping");
    		priceLabel=new Label("Your total amount is : $ "); 
    		pricedisplayLabel=new Label("$ 0");
    	
    	
    		// initilizing Text fields//
    		
    		pizzaText=new TextField("0",1);
    	
    		//initializing J Radio buttons//
    		
    		smallJRadio = new JRadioButton("Small", true);
    		mediumJRadio = new JRadioButton("medium", false);
    		largeJRadio = new JRadioButton("Large", false);
    		extralargeJRadio = new JRadioButton("extra Large", false);
    		
    		// initializing Group radio buttons//
    		
    		sizeBGroup = new ButtonGroup();
    		sizeBGroup.add(smallJRadio);
    		sizeBGroup.add(mediumJRadio);
    		sizeBGroup.add(largeJRadio);
    		sizeBGroup.add(extralargeJRadio);
    		
    		
    		// Initializing JCheckboxes
    		cheeseJCheck = new JCheckBox("Extra Cheese",false);
    		sausageJCheck = new JCheckBox("Sausage Slices",false);
    		mushroomJCheck = new JCheckBox("Button Mushroom",false);
    		pepperJCheck = new JCheckBox("Green Pepper",false);
    		chickenJCheck = new JCheckBox("Chicken Nugget",false);
    		
    		// initializing buttons//
    		
    		orderButton=new Button("Order Now");
    		resetButton=new Button("New form");
    		
    		// Add Action Listeners //
    		
    		smallJRadio.addActionListener(this);
    		mediumJRadio.addActionListener(this);
    		largeJRadio.addActionListener(this);
    		extralargeJRadio.addActionListener(this);
    		
    		cheeseJCheck.addActionListener(this);
    		sausageJCheck.addActionListener(this);
    		mushroomJCheck.addActionListener(this);
    		pepperJCheck.addActionListener(this);
    		chickenJCheck.addActionListener(this);
    		
    		
    		pizzaText.addKeyListener(this);
    		
    		orderButton.addActionListener(this);
    	}
    		
    
    	// Unused interface methods
    	public void keyTyped(KeyEvent e) { }
    	public void keyPressed(KeyEvent e) { }
    
    	/**
    	 * Perform validation check on user text input
    	 */
    	public void keyReleased(KeyEvent e) { 
    		
    		// Trap all non-valid numbers
    		try {
    			Integer.parseInt(pizzaText.getText());
    		}
    		catch (NumberFormatException fe) {
    			pizzaText.setText("0");
    		}
    		
    		refreshPrice();
    	}	
    	
    
    
    
    	public void actionPerformed(ActionEvent e){
    				
    		if (e.getSource() == orderButton) {
    				
    			JOptionPane.showMessageDialog(this,
    				"Thank you for your " + 
    				pricedisplayLabel.getText() + "  payment." +
    				"\n\nYour pizza will be delivered to you in 3 months !" + 
    				"\nWhy dont you order another pizza while waiting ?",
    				"Orders Confirmed",
    				JOptionPane.INFORMATION_MESSAGE);
    		}
    		
    		refreshPrice();
    	}
    		
    			private void refreshPrice() {
    		
    		// Local variables used to accumulate total price
    		int price = 0;
    		int pizzaAmount = Integer.parseInt(pizzaText.getText());
    		
    		// Pizza size prices
    		if (smallJRadio.isSelected()) {
    			price+= small * pizzaAmount;
    		}
    		
    		if (mediumJRadio.isSelected()) {
    			price+= medium * pizzaAmount;
    		}
    
    		if (largeJRadio.isSelected()) {
    			price+= large * pizzaAmount;
    		}
    			if (largeJRadio.isSelected()) {
    			price+= extralarge * pizzaAmount;
    		}
    		
    		
    		// Pizza topping prices
    		if (cheeseJCheck.isSelected()) {
    			price+= cheese * pizzaAmount;
    		}
    
    		if (sausageJCheck.isSelected()) {
    			price+= sausage * pizzaAmount;
    		}
    
    		if (mushroomJCheck.isSelected()) {
    			price+= mushroom * pizzaAmount;
    		}
    
    	
    
    		if (pepperJCheck.isSelected()) {
    			price+= pepper * pizzaAmount;
    		}
    
    		if (chickenJCheck.isSelected()) {
    			price+= chicken* pizzaAmount;
    		}
    
    		pricedisplayLabel.setText("$"+(price));
    		
    		
    
    		
    		}
    
    
    		
    		
    		
    	}

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You created a bunch on controls that you never added to the Applet at all. Creating them inside the init method doesn't count.
    Better add them to a panel with correct layout and add that panel to the applet.
    Much better is to get Sun's tutorial on applets and go through it first looking at the examples they give. That way you don't have to guess what the code should look like.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    When you're starting out writing programs for the first time, do the project in small steps to see how to use the various components and methods.
    For example, for this project start with a simple applet that displays a button and have a listener for the button print something when the button is pressed. Try different layout managers to see how they work.
    Then move on to the larger program and use what you've learned in the small programs.

  4. #4
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    Thanks guyz , ive found an article n based on that ive made my panels :
    Java Code:
    
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.text.*;
    import javax.swing.*;
    
    /**
     * This is the Pizza Ordering class
     */
    public class pizz extends Applet implements ActionListener, KeyListener {
    	 	
    	// Constants for storing Prices
    	private final double smallPizzaPrice = 9.00,
    				   		 regularPizzaPrice = 16.50,
    				   		 largePizzaPrice = 22.00,
    				   		 
    				   		 cheeseToppingPrice = 2.80,
    				   		 sausageToppingPrice = 2.80,
    				   		 mushroomToppingPrice = 2.30,
    				   		 oreganoToppingPrice = 3.00,
    				   		 pepperToppingPrice = 2.30,
    				   		 chickenToppingPrice = 3.00;
    		
    	//Graphical components
    	Panel topPanel,
    		  centerPanel,
    		  centerQuantityPanel,
    		  centerSizePanel,
    		  centerToppingPanel,
    		  centerPricePanel,
    		  bottomPanel;
    		
    	Label titleLabel,
    		  quantityLabel,
    		  amountLabel,
    		  sizeLabel,
    		  toppingLabel,
    		  priceLabel,
    		  priceDisplayLabel;
    		
    	Button orderButton;
    
    	TextField pizzaText,
    			  priceText;
    	
    	ButtonGroup sizeBGroup;
    	
    	JRadioButton smallJRadio,
    				 regularJRadio,
    				 largeJRadio;
    	
    	JCheckBox cheeseJCheck,
    			  sausageJCheck,
    			  mushroomJCheck,
    			  oreganoJCheck,
    			  pepperJCheck,
    			  chickenJCheck;
    
    	/**
    	 * Initialize variable and components
    	 */
    	public void init() {
    				
    		// Setting applet 
    		setBackground(new Color(205,205,205));
    		setLayout(new BorderLayout(0,0));
    						
    		// Initializing Panels
    		topPanel = new Panel();
    		topPanel.setBackground(new Color(0,118,157));
    		topPanel.setLayout(new FlowLayout());
    
    		centerPanel = new Panel();
    		
    		centerQuantityPanel = new Panel();
    		centerQuantityPanel.setLayout(new FlowLayout());
    		
    		centerSizePanel = new Panel();
    		centerSizePanel.setLayout(new FlowLayout());
    				
    		centerToppingPanel = new Panel();
    		centerToppingPanel.setLayout(new GridLayout(2,3,0,0));
    
    		centerPricePanel = new Panel();
    		centerPricePanel.setLayout(new FlowLayout());
    		
    		bottomPanel = new Panel();
    		bottomPanel.setLayout(new FlowLayout());
    			
    		// Initializing Labels
    		titleLabel = new Label("CyberPizza.com");
    		titleLabel.setBackground(new Color(0,118,157));
    		titleLabel.setForeground(new Color(255,255,255));
    		titleLabel.setFont(new Font("Arial",Font.BOLD,50));
    		
    		quantityLabel = new Label("Enter the number of pizza(s) you wish to order : ");
    		quantityLabel.setForeground(new Color(0,0,205));
    		quantityLabel.setFont(new Font("Arial",Font.BOLD,14));
    
    		amountLabel = new Label("Amount: ");
    		amountLabel.setForeground(new Color(0,0,0));
    		amountLabel.setFont(new Font("Arial",Font.BOLD,14));
    
    		sizeLabel = new Label("Select the size of the pizza(s) above to be made in :");
    		sizeLabel.setForeground(new Color(0,0,205));
    		sizeLabel.setFont(new Font("Arial",Font.BOLD,14));
    		
    		toppingLabel = new Label("Select one or more choices of the toppings below : ");
    		toppingLabel.setForeground(new Color(0,0,205));
    		toppingLabel.setFont(new Font("Arial",Font.BOLD,14));
    
    		priceLabel = new Label("Total price of your order : ");
    		priceLabel.setForeground(new Color(200,0,0));
    		priceLabel.setFont(new Font("Arial",Font.BOLD,14));
    
    		priceDisplayLabel = new Label("$0.00       ");
    		priceDisplayLabel.setForeground(new Color(235,0,0));
    		priceDisplayLabel.setFont(new Font("Arial",Font.BOLD,34));
    				
    		// Initializing Textfields
    		pizzaText = new TextField("0",1);
    		pizzaText.setFont(new Font("Arial",Font.BOLD,14));
    
    		// Initializing JRadio buttons
    		smallJRadio = new JRadioButton("Small", true);
    		regularJRadio = new JRadioButton("Regular", false);
    		largeJRadio = new JRadioButton("Large", false);
    		
    		// Grouping radio buttons
    		sizeBGroup = new ButtonGroup();
    		sizeBGroup.add(smallJRadio);
    		sizeBGroup.add(regularJRadio);
    		sizeBGroup.add(largeJRadio);
    		
    		// Initializing JCheckboxes
    		cheeseJCheck = new JCheckBox("Extra Cheese",false);
    		sausageJCheck = new JCheckBox("Sausage Slices",false);
    		mushroomJCheck = new JCheckBox("Button Mushroom",false);
    		oreganoJCheck = new JCheckBox("Oregano",false);
    		pepperJCheck = new JCheckBox("Green Pepper",false);
    		chickenJCheck = new JCheckBox("Chicken Nugget",false);
    		
    		// Initializing Buttons
    		orderButton = new Button("Order Now");
    		orderButton.setFont(new Font("Arial",Font.BOLD,16));
    				
    		// Registering listeners to components
    		smallJRadio.addActionListener(this);
    		regularJRadio.addActionListener(this);
    		largeJRadio.addActionListener(this);
    		
    		cheeseJCheck.addActionListener(this);
    		sausageJCheck.addActionListener(this);
    		mushroomJCheck.addActionListener(this);
    		oreganoJCheck.addActionListener(this);
    		pepperJCheck.addActionListener(this);
    		chickenJCheck.addActionListener(this);
    		
    		pizzaText.addKeyListener(this);
    		
    		orderButton.addActionListener(this);
    	}
    	
    	/**
    	 * Start of applet
    	 */
    	public void start() {
    		
    		// Top Panel
    		topPanel.add(titleLabel);
    		
    		// Nested Center Panels
    		centerQuantityPanel.add(amountLabel);
    		centerQuantityPanel.add(pizzaText);
    		
    		centerSizePanel.add(smallJRadio);
    		centerSizePanel.add(regularJRadio);
    		centerSizePanel.add(largeJRadio);
    		
    		centerToppingPanel.add(cheeseJCheck);
    		centerToppingPanel.add(sausageJCheck);
    		centerToppingPanel.add(mushroomJCheck);
    		centerToppingPanel.add(oreganoJCheck);
    		centerToppingPanel.add(pepperJCheck);
    		centerToppingPanel.add(chickenJCheck);
    		
    		centerPricePanel.add(priceLabel);
    		centerPricePanel.add(priceDisplayLabel);
    		
    		// Center Panel
    		centerPanel.add(quantityLabel);
    		centerPanel.add(centerQuantityPanel);
    		centerPanel.add(sizeLabel);
    		centerPanel.add(centerSizePanel);
    		centerPanel.add(toppingLabel);
    		centerPanel.add(centerToppingPanel);
    		centerPanel.add(centerPricePanel);
    		
    		// Bottom Panel
    		bottomPanel.add(orderButton);
    		
    		// Main Applet Window
    		add(topPanel, BorderLayout.NORTH);
    		add(centerPanel, BorderLayout.CENTER);
    		add(bottomPanel, BorderLayout.SOUTH);
    		
    		pizzaText.selectAll();
    	}
    
    	// Unused interface methods
    	public void keyTyped(KeyEvent e) { }
    	public void keyPressed(KeyEvent e) { }
    
    	/**
    	 * Perform validation check on user text input
    	 */
    	public void keyReleased(KeyEvent e) { 
    		
    		// Trap all non-valid numbers
    		try {
    			Integer.parseInt(pizzaText.getText());
    		}
    		catch (NumberFormatException fe) {
    			pizzaText.setText("0");
    		}
    		
    		refreshPrice();
    	}	
    	
    	/**
    	 * Traps user input
    	 */
    	public void actionPerformed(ActionEvent e) {
    		
    		// If order now button is pressed
    		if (e.getSource() == orderButton) {
    				
    			JOptionPane.showMessageDialog(this,
    				"Thank you for your " + 
    				priceDisplayLabel.getText() + "  payment." +
    				"\n\nYour pizza will be delivered to you in 3 months !" + 
    				"\nWhy dont you order another pizza while waiting ?",
    				"Orders Confirmed",
    				JOptionPane.INFORMATION_MESSAGE);
    		}
    		
    		refreshPrice();
    	}
    	
    	/**
    	 * Method to calculate and refresh the price display
    	 */
    	private void refreshPrice() {
    		
    		// Local variables used to accumulate total price
    		double price = 0;
    		int pizzaAmount = Integer.parseInt(pizzaText.getText());
    		
    		// Initializing Number Format		
    		NumberFormat numberForm = NumberFormat.getNumberInstance();
    		DecimalFormat moneyForm = (DecimalFormat)numberForm;
    		moneyForm.applyPattern("0.00");
    
    		// Pizza size prices
    		if (smallJRadio.isSelected()) {
    			price+= smallPizzaPrice * pizzaAmount;
    		}
    		
    		if (regularJRadio.isSelected()) {
    			price+= regularPizzaPrice * pizzaAmount;
    		}
    
    		if (largeJRadio.isSelected()) {
    			price+= largePizzaPrice * pizzaAmount;
    		}
    		
    		// Pizza topping prices
    		if (cheeseJCheck.isSelected()) {
    			price+= cheeseToppingPrice * pizzaAmount;
    		}
    
    		if (sausageJCheck.isSelected()) {
    			price+= sausageToppingPrice * pizzaAmount;
    		}
    
    		if (mushroomJCheck.isSelected()) {
    			price+= mushroomToppingPrice * pizzaAmount;
    		}
    
    		if (oreganoJCheck.isSelected()) {
    			price+= oreganoToppingPrice * pizzaAmount;
    		}
    
    		if (pepperJCheck.isSelected()) {
    			price+= pepperToppingPrice * pizzaAmount;
    		}
    
    		if (chickenJCheck.isSelected()) {
    			price+= chickenToppingPrice * pizzaAmount;
    		}
    
    		priceDisplayLabel.setText("$"+moneyForm.format(price));
    	}
    }

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Is there a question?
    Or have you finished your project?

  6. #6
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    thanks my problem's been solved :)

  7. #7
    shakira05 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Re: Pizza Order System

    can you guys help me to do an ordering system which allows a user to select their order in checkbox and appears the total price in textfield. please.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Pizza Order System

    Please start your own thread for this new project of yours.
    Be sure to add specific questions about the project and where you are having problems in creating the program.

Similar Threads

  1. How to order a vector?
    By tyang in forum New To Java
    Replies: 2
    Last Post: 02-06-2010, 08:24 AM
  2. Java Run Order
    By collin389 in forum New To Java
    Replies: 15
    Last Post: 11-24-2009, 07:22 AM
  3. Instantiation order
    By Jeremy720 in forum New To Java
    Replies: 3
    Last Post: 07-17-2009, 03:19 PM
  4. Descending order
    By santanu in forum New To Java
    Replies: 1
    Last Post: 11-04-2008, 04:33 PM
  5. Replies: 0
    Last Post: 07-22-2008, 04:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •