I get this when i click on the done button in my program:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at BillPanel.getTotalPrice(BillPanel.java:49)
	at BillPanel$ButtonListener.actionPerformed(BillPanel.java:62)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.Component.processMouseEvent(Component.java:6038)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
	at java.awt.Component.processEvent(Component.java:5803)
	at java.awt.Container.processEvent(Container.java:2058)
	at java.awt.Component.dispatchEventImpl(Component.java:4410)
	at java.awt.Container.dispatchEventImpl(Container.java:2116)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
	at java.awt.Container.dispatchEventImpl(Container.java:2102)
	at java.awt.Window.dispatchEventImpl(Window.java:2429)
	at java.awt.Component.dispatchEvent(Component.java:4240)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

what does it mean?

here is my program:

//PizzaDemo.java		Author: Carien Anderson

import javax.swing.*;

public class PizzaDemo
{
	//sets up frame with tabbed pane
	public static void main (String[] args)
	{
		JFrame frame = new JFrame("Pizza Demo");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JTabbedPane tP = new JTabbedPane();
		tP.addTab ("Pizza", new PizzaPanel());
		tP.addTab ("Beverages", new BeveragePanel());
		tP.addTab ("Special Items", new SpecialPanel());
		tP.addTab ("Bill", new BillPanel());
		frame.getContentPane().add(tP);
		frame.pack();
		frame.setVisible(true);
	}
}
//PizzaPanel.java		Author: Carien Anderson

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import java.awt.event.*;

public class PizzaPanel extends JPanel
{
	int again;
	private JButton button;
	private JTextField quantitynum;
	private JPanel ppan1,ppan2, quantityPanel, sizePanel, topping, exitPanel;
	private JRadioButton small, large, medium;
	double Price;
	
	public PizzaPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.white);
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		ppan1 = new JPanel();
		JLabel l1 = new JLabel("Lets Eat!");
		ppan1.add(l1);
		ppan1.setBackground(Color.green);
		add(ppan1, BorderLayout.NORTH);
		
		//West panel
		ppan2 = new JPanel();
		
		quantityPanel = new JPanel();
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		quantityPanel.setBackground(Color.red);
		quantityPanel.add(quantity);
		quantityPanel.add(quantitynum);
		
		
		sizePanel = new JPanel();
		JLabel size = new JLabel("Size: ");
		JRadioButton small = new JRadioButton ("Small");
		JRadioButton medium = new JRadioButton ("Medium");
		JRadioButton large = new JRadioButton ("Large");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (small);
		group1.add (medium);
		group1.add (large);
	   sizePanel.setBackground(Color.red);
		sizePanel.add(size);
		sizePanel.add(small);
		sizePanel.add(medium);
		sizePanel.add(large);
		
		ppan2.add(quantityPanel);
		ppan2.add(sizePanel);
	
		ppan2.setLayout (new BoxLayout(ppan2, BoxLayout.Y_AXIS));
		ppan2.setBackground(Color.red);
		add (ppan2, BorderLayout.WEST);
		
		//Center
	   topping = new JPanel();
		topping.setLayout (new BoxLayout (topping, BoxLayout.Y_AXIS));
		topping.setBackground (Color.red);
		TitledBorder border2 = BorderFactory.createTitledBorder ("Toppings");
		border2.setTitleJustification (TitledBorder.LEFT);
		topping.setAlignmentY(Component.CENTER_ALIGNMENT);
		topping.setPreferredSize(new Dimension (80,75));
		JCheckBox peperonni = new JCheckBox("Peperonni");
		JCheckBox sausage = new JCheckBox("Sausage");
		JCheckBox onion = new JCheckBox("Onion");
		JCheckBox ham = new JCheckBox("Ham");
		JCheckBox mushroom = new JCheckBox("Mushroom");
		JCheckBox pepper = new JCheckBox("Peppers");
		topping.setBorder(border2);
		peperonni.setBackground(Color.red);
		sausage.setBackground(Color.red);
		onion.setBackground(Color.red);
		ham.setBackground(Color.red);
		mushroom.setBackground(Color.red);
		pepper.setBackground(Color.red);
		topping.add(peperonni);
		topping.add(sausage);
		topping.add(onion);
		topping.add(ham);
		topping.add(mushroom);
		topping.add(pepper);
		
		add(topping, BorderLayout.CENTER);		
		
		
		//South
	   exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.green);
		exitPanel.add(Box.createHorizontalGlue());
		button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);

		add(exitPanel, BorderLayout.SOUTH);
				
	}
	
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
				if (event.getSource() == small)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
					
					System.out.println("The price for the pizza is" + Price);
				}
				
				else if (event.getSource() == medium)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
				}
				
				else if  (event.getSource() == large)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
				}
								
				else
				{
					again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
					if (again == JOptionPane.YES_OPTION)
					System.exit(0);
				}
			
		}
	}
	
	public double setPrice()
	{
		return(Price);
	}
}
//BeveragePanel.java 	Author: Carien Anderson

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

public class BeveragePanel extends JPanel
{
	int again;
	private JPanel bpan1, bpan2, quantityPanel, sizePanel,drinkPanel, exitPanel;
	private JTextField quantitynum;
	private JRadioButton small, medium, large;
	double Price;
	
	public BeveragePanel()
	{
		setLayout(new BorderLayout());
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		bpan1 = new JPanel();
		JLabel l1 = new JLabel("Quinch your thirst!!!!");
		bpan1.setBackground (Color.yellow);
		bpan1.add(l1);
		add(bpan1, BorderLayout.NORTH);
		
		//Center panel
		bpan2 = new JPanel();
		
		quantityPanel = new JPanel();
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		quantityPanel.setBackground(Color.red);
		quantityPanel.add(quantity);
		quantityPanel.add(quantitynum);

		sizePanel = new JPanel();
		JLabel size = new JLabel("Size: ");
	   small = new JRadioButton ("Small");
	   medium = new JRadioButton ("Medium");
		large = new JRadioButton ("Large");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (small);
		group1.add (medium);
		group1.add (large);
	   sizePanel.setBackground(Color.red);
		sizePanel.add(size);
		sizePanel.add(small);
		sizePanel.add(medium);
		sizePanel.add(large);
		
		
		drinkPanel = new JPanel();
		JLabel drink = new JLabel("Drinks: ");
		String[] type2 = {"Sprite", "Dr. Pepper", "Coke", "Hi-C Orange", "Coco Cola"};
		JComboBox drinkType = new JComboBox (type2);
		drinkPanel.setBackground (Color.white);
		drinkPanel.add(drink);
		drinkPanel.add(drinkType);
		
		bpan2.add(quantityPanel);
		bpan2.add(sizePanel);
		bpan2.add(drinkPanel);
		
		bpan2.setLayout (new BoxLayout(bpan2, BoxLayout.Y_AXIS));
		add (bpan2, BorderLayout.CENTER);
		
		//South
		exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.yellow);
		exitPanel.add(Box.createHorizontalGlue());
		JButton button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);
		add(exitPanel, BorderLayout.SOUTH);
		

	}
	
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
		
			if (event.getSource() == small)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*1.00;
				}
				
				else if (event.getSource() == medium)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*1.50;
				}
				
				else if  (event.getSource() == large)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*2.00;
				}
				else
				{
					again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
					if (again == JOptionPane.YES_OPTION)
					System.exit(0);
				}
		}
	}
	
	public double setPrice()
	{
		return(Price);
	}

}
//SpecialPanel.java 	Author: Carien Anderson


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

public class SpecialPanel extends JPanel
{
	int again;
	private JPanel span1, span2, quantityPanel, sidePanel, exitPanel;
	private JTextField quantitynum;
	private JRadioButton wings, salad, bread;
	double Price;
	
	public SpecialPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.blue);
		
		//North panel
		JPanel span1 = new JPanel();
		JLabel l1 = new JLabel("Something Extra!!");
		span1.add(l1);
		span1.setBackground(Color.white);
		add(span1, BorderLayout.NORTH);
		
		sidePanel = new JPanel();
		JLabel side = new JLabel("Choose a side: ");
		wings = new JRadioButton ("wings");
		salad = new JRadioButton ("salad");
		bread = new JRadioButton ("breadsticks");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (wings);
		group1.add (salad);
		group1.add (bread);
	   sidePanel.setBackground(Color.red);
		sidePanel.add(side);
		sidePanel.add(wings);
		sidePanel.add(salad);
		sidePanel.add(bread);
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		sidePanel.add(quantity);
		sidePanel.add(quantitynum);

		add(sidePanel, BorderLayout.CENTER);
			
		//South
		exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.white);
		exitPanel.add(Box.createHorizontalGlue());
		JButton button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);
		
		add(exitPanel, BorderLayout.SOUTH);
		
	}
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == wings)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*0.80;
				}
				
				else if (event.getSource() == salad)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*2.15;
				}
				
				else if  (event.getSource() == bread)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.75;
				}
			else
			{		
				again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
				if (again == JOptionPane.YES_OPTION)
				System.exit(0);
			}

		}
	}
	
	public double setPrice()
	{
		return(Price);
	}

}
//BillPanel.java 	Author: Carien Anderson


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

public class BillPanel extends JPanel
{
	int again;
	private JButton button, button1;
	private BeveragePanel tp;
	private SpecialPanel tq;
	private PizzaPanel tr;
	
	public BillPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.white);
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		JPanel ppan1 = new JPanel();
		JLabel l1 = new JLabel("Reciept!");
		ppan1.add(l1);
		ppan1.setBackground(Color.orange);
		add(ppan1, BorderLayout.NORTH);
		
		//South
		JPanel exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.orange);
		exitPanel.add(Box.createHorizontalGlue());
		button = new JButton ("Logout");
		button1 = new JButton ("Done");
		exitPanel.add(button1);
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button1.addActionListener (listener);
		button.addActionListener (listener);
		
		add(exitPanel, BorderLayout.SOUTH);
					
	}
	
	public double getTotalPrice()
	{
		return (tr.setPrice() + tp.setPrice() + tq.setPrice());
	}
		
	private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == button1)
			{
				System.out.println("Total: " + getTotalPrice());
			}
			else 
			{
				again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
				if (again == JOptionPane.YES_OPTION)
					System.exit(0);
			}
		}
	}
	}

Recommended Answers

All 5 Replies

It means that, at the line where you got that error, you are trying to use a variable which has not been initialized.

thanks but i really dont see what it is that i am missing? :-(

return (tr.setPrice() + tp.setPrice() + tq.setPrice());

If you look in your BillPanel class, you never initialized any of those variables. Therefore, there contents are null, and you are getting a NullPointerException. How do you expect to say tr.setPrice() when you never created "tr"? Essentially tr at that point is just an empty variable with nothing in it. You have to say tr = new PizzaPanel() at some point in your code before you try to use the variable tr. The same goes for all of your other variables.

I have redone this entire program and now i have no exceptions no errors but when i click the done button to show the price this is what i get

The total is: Total[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]

here is my program redo:

//PizzaDemo.java		Author: Carien Anderson

import javax.swing.*;

public class PizzaDemo
{
	//sets up frame with tabbed pane
	public static void main (String[] args)
	{
		JFrame frame = new JFrame("Pizza Demo");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JTabbedPane tP = new JTabbedPane();
		tP.addTab ("Pizza", new PizzaPanel());
		tP.addTab ("Beverages", new BeveragePanel());
		tP.addTab ("Special Items", new SpecialPanel());
		tP.addTab ("Bill", new BillPanel());
		
		frame.getContentPane().add(tP);
		frame.pack();
		frame.setVisible(true);
	}
}
//PizzaPanel.java		Author: Carien Anderson

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import java.awt.event.*;

public class PizzaPanel extends JPanel
{
	int again;
	private JButton button;
	private JTextField quantitynum;
	private JPanel ppan1,ppan2, quantityPanel, sizePanel, topping, exitPanel;
	private JRadioButton small, large, medium;
	double Price;
	
	public PizzaPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.white);
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		ppan1 = new JPanel();
		JLabel l1 = new JLabel("Lets Eat!");
		ppan1.add(l1);
		ppan1.setBackground(Color.green);
		add(ppan1, BorderLayout.NORTH);
		
		//West panel
		ppan2 = new JPanel();
		
		quantityPanel = new JPanel();
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		quantityPanel.setBackground(Color.red);
		quantityPanel.add(quantity);
		quantityPanel.add(quantitynum);
		
		
		sizePanel = new JPanel();
		JLabel size = new JLabel("Size: ");
		JRadioButton small = new JRadioButton ("Small");
		JRadioButton medium = new JRadioButton ("Medium");
		JRadioButton large = new JRadioButton ("Large");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (small);
		group1.add (medium);
		group1.add (large);
	   sizePanel.setBackground(Color.red);
		sizePanel.add(size);
		sizePanel.add(small);
		sizePanel.add(medium);
		sizePanel.add(large);
		
		ppan2.add(quantityPanel);
		ppan2.add(sizePanel);
	
		ppan2.setLayout (new BoxLayout(ppan2, BoxLayout.Y_AXIS));
		ppan2.setBackground(Color.red);
		add (ppan2, BorderLayout.WEST);
		
		//Center
	   topping = new JPanel();
		topping.setLayout (new BoxLayout (topping, BoxLayout.Y_AXIS));
		topping.setBackground (Color.red);
		TitledBorder border2 = BorderFactory.createTitledBorder ("Toppings");
		border2.setTitleJustification (TitledBorder.LEFT);
		topping.setAlignmentY(Component.CENTER_ALIGNMENT);
		topping.setPreferredSize(new Dimension (80,75));
		JCheckBox peperonni = new JCheckBox("Peperonni");
		JCheckBox sausage = new JCheckBox("Sausage");
		JCheckBox onion = new JCheckBox("Onion");
		JCheckBox ham = new JCheckBox("Ham");
		JCheckBox mushroom = new JCheckBox("Mushroom");
		JCheckBox pepper = new JCheckBox("Peppers");
		topping.setBorder(border2);
		peperonni.setBackground(Color.red);
		sausage.setBackground(Color.red);
		onion.setBackground(Color.red);
		ham.setBackground(Color.red);
		mushroom.setBackground(Color.red);
		pepper.setBackground(Color.red);
		topping.add(peperonni);
		topping.add(sausage);
		topping.add(onion);
		topping.add(ham);
		topping.add(mushroom);
		topping.add(pepper);
		
		add(topping, BorderLayout.CENTER);		
		
		
		//South
	   exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.green);
		exitPanel.add(Box.createHorizontalGlue());
		button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);

		add(exitPanel, BorderLayout.SOUTH);
				
	}
	
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
				if (event.getSource() == small)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
					
					System.out.println("The price for the pizza is" + Price);
				}
				
				else if (event.getSource() == medium)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
				}
				
				else if  (event.getSource() == large)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price=quantity*3.50;
				}
								
				else
				{
					again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
					if (again == JOptionPane.YES_OPTION)
					System.exit(0);
				}
			
		}
	}
		public double setPrice()
	{
		return(Price);
	}
}
//BeveragePanel.java 	Author: Carien Anderson

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

public class BeveragePanel extends JPanel
{
	int again;
	private JPanel bpan1, bpan2, quantityPanel, sizePanel,drinkPanel, exitPanel;
	private JTextField quantitynum;
	private JRadioButton small, medium, large;
	double Price1;
	
	public BeveragePanel()
	{
		setLayout(new BorderLayout());
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		bpan1 = new JPanel();
		JLabel l1 = new JLabel("Quinch your thirst!!!!");
		bpan1.setBackground (Color.yellow);
		bpan1.add(l1);
		add(bpan1, BorderLayout.NORTH);
		
		//Center panel
		bpan2 = new JPanel();
		
		quantityPanel = new JPanel();
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		quantityPanel.setBackground(Color.red);
		quantityPanel.add(quantity);
		quantityPanel.add(quantitynum);

		sizePanel = new JPanel();
		JLabel size = new JLabel("Size: ");
	   small = new JRadioButton ("Small");
	   medium = new JRadioButton ("Medium");
		large = new JRadioButton ("Large");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (small);
		group1.add (medium);
		group1.add (large);
	   sizePanel.setBackground(Color.red);
		sizePanel.add(size);
		sizePanel.add(small);
		sizePanel.add(medium);
		sizePanel.add(large);
		
		
		drinkPanel = new JPanel();
		JLabel drink = new JLabel("Drinks: ");
		String[] type2 = {"Sprite", "Dr. Pepper", "Coke", "Hi-C Orange", "Coco Cola"};
		JComboBox drinkType = new JComboBox (type2);
		drinkPanel.setBackground (Color.white);
		drinkPanel.add(drink);
		drinkPanel.add(drinkType);
		
		bpan2.add(quantityPanel);
		bpan2.add(sizePanel);
		bpan2.add(drinkPanel);
		
		bpan2.setLayout (new BoxLayout(bpan2, BoxLayout.Y_AXIS));
		add (bpan2, BorderLayout.CENTER);
		
		//South
		exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.yellow);
		exitPanel.add(Box.createHorizontalGlue());
		JButton button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);
		add(exitPanel, BorderLayout.SOUTH);
		

	}
	
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
		
			if (event.getSource() == small)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price1=quantity*1.00;
				}
				
				else if (event.getSource() == medium)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price1=quantity*1.50;
				}
				
				else if  (event.getSource() == large)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price1=quantity*2.00;
				}
				else
				{
					again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
					if (again == JOptionPane.YES_OPTION)
					System.exit(0);
				}
		}
	}
		public double setPrice1()
	{
		return(Price1);
	}
}
//SpecialPanel.java 	Author: Carien Anderson


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

public class SpecialPanel extends JPanel
{
	int again;
	private JPanel span1, span2, quantityPanel, sidePanel, exitPanel;
	private JTextField quantitynum;
	private JRadioButton wings, salad, bread;
	double Price2;
	
	public SpecialPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.blue);
		
		//North panel
		JPanel span1 = new JPanel();
		JLabel l1 = new JLabel("Something Extra!!");
		span1.add(l1);
		span1.setBackground(Color.white);
		add(span1, BorderLayout.NORTH);
		
		sidePanel = new JPanel();
		JLabel side = new JLabel("Choose a side: ");
		wings = new JRadioButton ("wings");
		salad = new JRadioButton ("salad");
		bread = new JRadioButton ("breadsticks");
		ButtonGroup group1 = new ButtonGroup();
		group1.add (wings);
		group1.add (salad);
		group1.add (bread);
	   sidePanel.setBackground(Color.red);
		sidePanel.add(side);
		sidePanel.add(wings);
		sidePanel.add(salad);
		sidePanel.add(bread);
		JLabel quantity = new JLabel ("Quantity: ");
		quantitynum = new JTextField(5);
		sidePanel.add(quantity);
		sidePanel.add(quantitynum);

		add(sidePanel, BorderLayout.CENTER);
			
		//South
		exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.white);
		exitPanel.add(Box.createHorizontalGlue());
		JButton button = new JButton ("Logout");
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button.addActionListener (listener);
		
		add(exitPanel, BorderLayout.SOUTH);
		
	}
		private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == wings)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price2=quantity*0.80;
				}
				
				else if (event.getSource() == salad)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price2=quantity*2.15;
				}
				
				else if  (event.getSource() == bread)
				{
					int quantity;
					
					String text = quantitynum.getText();
					
					quantity = Integer.parseInt (text);
					
					Price2=quantity*3.75;
				}
			else
			{		
				again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
				if (again == JOptionPane.YES_OPTION)
				System.exit(0);
			}

		}
	}
		public double setPrice2()
	{
		return(Price2);
	}
}
//BillPanel.java 	Author: Carien Anderson


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

public class BillPanel extends JPanel
{
	int again;
	private JButton button, button1;
	private BeveragePanel tp;
	private SpecialPanel tq;
	private PizzaPanel tr;
	Total TotalPrice;
	
	public BillPanel()
	{
		setLayout(new BorderLayout());
		setBackground (Color.white);
		setPreferredSize (new Dimension(700,280));
		
		//North panel
		JPanel ppan1 = new JPanel();
		JLabel l1 = new JLabel("Reciept!");
		ppan1.add(l1);
		ppan1.setBackground(Color.orange);
		add(ppan1, BorderLayout.NORTH);
		
		
		//South
		JPanel exitPanel = new JPanel();
		exitPanel.setLayout(new BoxLayout (exitPanel, BoxLayout.X_AXIS));
		exitPanel.setBackground (Color.orange);
		exitPanel.add(Box.createHorizontalGlue());
		button = new JButton ("Logout");
		button1 = new JButton ("Done");
		exitPanel.add(button1);
		exitPanel.add(button);
		ButtonListener listener = new ButtonListener();
		button1.addActionListener (listener);
		button.addActionListener (listener);
		
		add(exitPanel, BorderLayout.SOUTH);
		
		tr= new PizzaPanel();
		tp = new BeveragePanel();
		tq= new SpecialPanel();
		
		TotalPrice = new Total(tr.setPrice(), tp.setPrice1(), tq.setPrice2());
					
	}
	private class ButtonListener implements ActionListener
	{
		//----------------------------------------------------------
		//	Determines which button was pressed and sets the label
		//	text accordingly.
		//----------------------------------------------------------
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == button1)
			{
			
				System.out.println("The total is: " + TotalPrice);
			
			}
			else 
			{
				again = JOptionPane.showConfirmDialog (null, "Do you want to quit?");
				if (again == JOptionPane.YES_OPTION)
					System.exit(0);
			}
		}
	}	
}
//TotalPanel.java 	Author: Carien Anderson


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

public class Total extends JPanel
{
	private double PizzaPrice, BeveragePrice, SidePrice, Total;
	
	public Total(double Price1, double Price2, double Price3)
	{
		PizzaPrice=Price1;
		BeveragePrice=Price2;
		SidePrice=Price3;
	}
	
	public void setTotalPrice(double Total)
	{
		Total= PizzaPrice+ BeveragePrice + SidePrice;
	}
	
	public double getTotal()
	{
		return Total;
	}
}

why is the output like that?

return (tr.setPrice() + tp.setPrice() + tq.setPrice());

If you look in your BillPanel class, you never initialized any of those variables. Therefore, there contents are null, and you are getting a NullPointerException. How do you expect to say tr.setPrice() when you never created "tr"? Essentially tr at that point is just an empty variable with nothing in it. You have to say tr = new PizzaPanel() at some point in your code before you try to use the variable tr. The same goes for all of your other variables.

that really helped now my output is wrong...look at my new reply please

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.