Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well my English is not that good but i will try to clarify myself. I am trying to build Spaza shop system and it cant display the image on the button menu1, menu2, and menu3 as well the buttons for proceed and cancel. Also, i want the button for start menu when it is clicked to display list of other items to be sold in the spaza shop. I am new in java, so some of mistakes i cant be able to correct them. Here is mycode:
Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wing_cafe;

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.text.*;
 import java.util.Date;
 import java.lang.reflect.InvocationTargetException;

public class wing_cafe extends JFrame implements ActionListener
{
    private GridBagLayout layout;
    private GridBagConstraints cons;
    private Container container;
    Thread th=new Thread();
    public static JList foodList;
    public static DefaultListModel appendList =new DefaultListModel();
    public static JButton other;
    public static double change=0.0;

    JButton panel1= new JButton();
    JPanel panel2= new JPanel();
    JPanel menu= new JPanel();
    JPanel payment= new JPanel();
    JButton done= new JButton("DONE");
    JButton exit= new JButton("EXIT");
    JLabel order= new JLabel("Ordered");
    public static JTextArea orderText= new JTextArea(2,8);
    JLabel amount= new JLabel("Enter amount to pay");
    public static JTextField amountText= new JTextField(8);
    JLabel orderTotal= new JLabel("Ordered Total");
    public static JTextField orderTotalText= new JTextField(8);
    JLabel changeL= new JLabel("Change");
    public static JTextField changeText= new JTextField(8);
    JButton ok= new JButton("proceed");
    JButton cancel= new JButton("Cancel");
    public static JTextField field1,timeField,timer,calc;
    JLabel label=new JLabel();

    JPanel a1= new JPanel();
    JPanel b1= new JPanel();
    JPanel c1= new JPanel();
    JPanel d1= new JPanel();
    JPanel e1= new JPanel();



    //JMenus,MenuBars and MenuItems declarations and methods
    JMenuBar mb=new JMenuBar();
    JMenu print=new JMenu("Reciept");
    JMenu help=new JMenu("Help!");
    JMenu manage=new JMenu("Database management");
    JMenuItem receipt=new JMenuItem("print reciept");
    JMenuItem aboutItem=new JMenuItem("About the program");
    JMenuItem usage=new JMenuItem("Help Message");
    JMenuItem mng=new JMenuItem("Management");


    //ClockAnimation clock=new ClockAnimation();
    CafeCalculation calculate=new CafeCalculation();
    selectMenu fmenu=new selectMenu();
    Progressbar bar=new Progressbar();

    public wing_cafe()
    {
        setTitle("Wings Cafe System");
        cons= new GridBagConstraints();
        container = getContentPane();
        layout = new GridBagLayout();
        container.setLayout( layout );
        container.setBackground(Color.BLACK);

        setJMenuBar(mb);
        manage.setIcon(new ImageIcon("images/loc.png"));
        help.setIcon(new ImageIcon("images/help.png"));
	print.setIcon(new ImageIcon("images/printer.png"));
	aboutItem.setIcon(new ImageIcon("images/helpA.png"));
	usage.setIcon(new ImageIcon("images/helpC.png"));
        mb.add(help);
        mb.add(print);
        mb.add(manage);
        help.add(aboutItem);
        help.add(usage);
        manage.add(mng);
        print.add(receipt);
        receipt.addActionListener(

             new ActionListener() {  // anonymous inner class

              // display message dialog when user selects About...
                public void actionPerformed( ActionEvent event )
                {
                	try{
        	        if(changeText.getText().equals("")||amountText.getText().equals("")||orderTotalText.getText().equals("")){
        		      throw new Throwable();
                        }
                   Progressbar.answer( );
                     }

                     catch(Throwable b){
            	JOptionPane.showMessageDialog(null,"Please fill up all transactions to complete","Notice!",JOptionPane.ERROR_MESSAGE);
                        }
             }  // end anonymous inner class
             }
          ); // end call to addActionListener



        manage.addActionListener(

             new ActionListener() {  // anonymous inner class

              // display message dialog when user selects About...
                public void actionPerformed( ActionEvent event )
                {
                   password();
                }

             }  // end anonymous inner class

          ); // end call to addActionListener
		//addAction listener to about item
          aboutItem.addActionListener(

             new ActionListener() {  // anonymous inner class

              // display message dialog when user selects About...
                public void actionPerformed( ActionEvent event )
                {
                   JOptionPane.showMessageDialog( wing_cafe.this,
                      "This is a complete Project developed by FELAPHE SEQHIBI, LEFU NTOA and TSOEU REMAKETSE  ",
                      "About", JOptionPane.PLAIN_MESSAGE );
                }

             }  // end anonymous inner class

          );

          usage.addActionListener(

             new ActionListener() {  // anonymous inner class

              // display message dialog when user selects About...
                public void actionPerformed( ActionEvent event )
                {
                   hlpmsg();
                }

             }  // end anonymous inner class

          ); // end call to addActionListener

           

        cons.weightx=1;
        cons.weighty=1;
        cons.fill=GridBagConstraints.BOTH;
        panel1.setBackground(Color.black);
        panel1.setIcon(new ImageIcon("images/menu.png"));
        addComponent(panel1,0,0 ,1,1);
        //addComponent(panel1);

        cons.weightx=1;
        cons.weighty=1;
        cons.fill=GridBagConstraints.BOTH;
        panel2.setBackground(Color.green);
        addComponent(panel2,0,1,1,1);

        cons.weightx=2;
        cons.weighty=2;
        cons.fill=GridBagConstraints.BOTH;
        JButton startMenu= new JButton("startMenu");
        JButton menu1= new JButton("Drink= M8.00",new ImageIcon("images/drink.jpg"));
        JButton menu2= new JButton("Pizza= M20.00",new ImageIcon("images/pizza.jpg"));
        JButton menu3= new JButton("Burger= M16.00",new ImageIcon("images/burger.jpg"));
        menu1.setBackground(Color.black);
        menu1.setForeground(Color.white);
        menu2.setBackground(Color.black);
        menu2.setForeground(Color.white);
        menu3.setBackground(Color.black);
        menu3.setForeground(Color.white);
        startMenu.setBackground(Color.black);
        startMenu.setForeground(Color.white);
        startMenu.addActionListener(this);
        menu1.addActionListener(this);
        menu2.addActionListener(this);
        menu3.addActionListener(this);
        menu.setLayout(new GridLayout(2,2));
        menu.add(startMenu);
        menu.add(menu1);
        menu.add(menu2);
        menu.add(menu3);
        addComponent(menu,1,0 ,1,1);

        cons.weightx=2;
        cons.weighty=2;
        cons.fill=GridBagConstraints.BOTH;
        payment.setLayout(new GridLayout(5,1));
        orderText.setEditable(false);
        orderTotalText.setEditable(false);
        changeText.setEditable(false);
        order.setForeground(Color.white);
        orderTotal.setForeground(Color.white);
        amount.setForeground(Color.white);
        changeL.setForeground(Color.white);
        c1.setLayout(new FlowLayout());
        c1.add(order);
        c1.add(orderText);
        c1.setBackground(Color.black);
        a1.setLayout(new FlowLayout());
        a1.add(orderTotal);
        a1.add(orderTotalText);
        a1.setBackground(Color.black);
        b1.setLayout(new FlowLayout());
        b1.add(amount);
        b1.add(amountText);
        b1.setBackground(Color.black);
        d1.setLayout(new FlowLayout());
        d1.add(changeL);
        d1.add(changeText);
        d1.setBackground(Color.black);
        e1.setLayout(new GridLayout(1,2));
        d1.setBackground(Color.black);
        ok.setBackground(Color.WHITE);
        cancel.setBackground(Color.WHITE);
        //cancel.setIcon(new ImageIcon("images/cancel.png"));
        ok.addActionListener(this);
        cancel.addActionListener(this);
        e1.add(ok);
        e1.add(cancel);
        payment.add(c1);
        payment.add(a1);
        payment.add(b1);
        payment.add(d1);
        payment.add(e1);
        addComponent(payment,1,1 ,1,1);

        cons.weightx=0.1;
        cons.weighty=0.1;
        cons.fill=GridBagConstraints.CENTER;
        done.setBackground(Color.WHITE);
        addComponent(done,2,0 ,1,1);
        done.addActionListener(this);

        cons.weightx=0.1;
        cons.weighty=0.1;
        cons.fill=GridBagConstraints.CENTER;
        exit.setBackground(Color.WHITE);
        //exit.setIcon(new ImageIcon("images/cancelb.png"));
        addComponent(exit,2,1 ,1,1);
        exit.addActionListener(this);

       

       

    }


  public void SwingAnimator(){
  try{
  for(int i = 1; i <= 5; i++){
  ImageIcon images = new ImageIcon("images/img" + i + ".gif");
  label.setIcon(images);
  th.sleep(6000);
  }
  }
  catch(InterruptedException e){}
  }

	// add a Component to the container
      /* private void addComponent( Component component )
       {
          layout.setConstraints( component, cons );
          container.add( component );      // add component
       }*/

        public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();

        // Container contentPane = getContentPane();

          //burger
        if (actionCommand.equals("Burger= M16.00"))
        {
            try
            {
               calculate.burger();
            }
            //catch (exception ex)

            catch (Exception ex)
            {

            }
        }
        	//drinks
        else if (actionCommand.equals("Drink= M8.00"))
        {

            try
            {
               calculate.Drinks();
            }
            //catch (exception ex)

            catch (Exception ex)
            {

            }
        }
        	 else if (actionCommand.equals("Pizza= M20.00"))
        {

            try
            {
              calculate.Pizza();
            }
            //*catch (exception ex)

            catch (Exception ex)
            {

            }
        }
        	//chips
        	 else if (actionCommand.equals("Chips= M10.00"))
        {

            try
            {
               calculate.Chips();
            }
            //*catch (exception ex)

            catch (Exception ex)
            {

            }
        }

        	//actions for buttons pon panelList
        	//for ok

        	 else if (actionCommand.equals("proceed"))
        {

            try
            {    Double c=Double.parseDouble(amountText.getText());
            	 Double a=Double.parseDouble(orderTotalText.getText());
            	 change=c-a;
            	 	if(a>c){
            	 		throw new Throwable();
            	 	}
               changeText.setText(""+change+"0");
            }
            //catch (exception ex for change)

            catch (Exception ex)
            {

               	JOptionPane.showMessageDialog(null,"Please fill up the amount in amount column","Notice!",JOptionPane.ERROR_MESSAGE);

            }
            catch(Throwable a){
            	JOptionPane.showMessageDialog(null,"SORRY, you don't have enough cash! insert more cash to continue ","Notice!",JOptionPane.ERROR_MESSAGE);
            }
        }
        	//for cancel


        	 else if (actionCommand.equals("Cancel"))
        {

            try
            {
               changeText.setText("");
               amountText.setText("");
               orderTotalText.setText("");
               calculate.totalAmount=0.0;
               calculate.amount=0.0;
               calculate.totalAmnt=0.0;
               // remove all from food from model
                appendList.clear();


            }
            //catch exeptions
            catch (Exception ex)
            {
               JOptionPane.showMessageDialog(null,"Error","Notice!",JOptionPane.ERROR_MESSAGE);
            }
        }

        else if(actionCommand.equals("."))
        {

        	try{

        		fmenu.setVisible(true);
        	}

        	catch (Exception ex){
        		JOptionPane.showMessageDialog(null,"Error","Notice!",JOptionPane.ERROR_MESSAGE);
        	}
        }

        //proceed button
         else if (actionCommand.equals("DONE"))
        {
        	try{
        	if(changeText.getText().equals("")||amountText.getText().equals("")||orderTotalText.getText().equals("")){
        		throw new Throwable();
        	}

    bar.setVisible(true);
    bar.panel.setVisible(true);
   	bar.panel.setSize(250,90);
   	bar.panel.setLayout(new FlowLayout());
    bar.panel.add(bar.pbr);
    bar.setSize(250,90);
    bar.add(bar.panel,BorderLayout.SOUTH);
    dispose();

	Thread stepper=new control(bar.pbr);
	stepper.start();

	}
            //catch (exception ex for change)


            catch(Throwable b){
            	JOptionPane.showMessageDialog(null,"PRESS OK TO CONTINUE!!! try to fillup all Transactions","Notice!",JOptionPane.ERROR_MESSAGE);
            }
        }

        else if(actionCommand.equals("EXIT"))
        {
        		System.exit(0);

        }
        	//gor for last else statement
        else
        {
            System.out.println("Error in button interface.");
        }

    }


    public static void main(String[] args)
    {
        // TODO code application logic here
        wing_cafe frame= new wing_cafe();
        frame.setSize(800, 750);
       frame.setVisible(true);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    private void addComponent(Component component, int row, int col, int width, int height)
    {
        cons.gridx=col;
        cons.gridy= row;
        cons.gridheight= height;
        cons.gridwidth= width;
        layout.setConstraints(component, cons);
        container.add( component );
    }


    	public void hlpmsg( ){

	  String outPut ="HOW TO MAKE AN ORDER IN KAPITSENG RESTURANT\n\n?"+
	                 "Please! CLICK on start menu and choose the meal you want to oder!\n"+
	  	              " quantity frame then insert quantity of things you buy, meaning number of them.\n"+
	                  " ENTER 1 if you don't want to change the quantity,\n" +
	                  "	\nchange the quantity number then ok if you want to change it.0 to EXIT\n"+
	                  " after selecting menu, the total will be on total order field,\n"+
	                  " insert the money you want to pay then your change will be \n"+
	                  "calculated for you. print reciept then Proceed to send to database.";


           JTextArea content = new JTextArea();
           content.setText(outPut );
			  content.setBackground(Color.GREEN);
			  content.setForeground(Color.WHITE);
		      content.setEditable(false);
		   JOptionPane.showMessageDialog( null, content,
              "How to use", JOptionPane.INFORMATION_MESSAGE );

	}

    //some classes

    /*******************************************
    	     PROGRESSBAR CLASS
    ********************************************/


    //progress bar class
   private class control extends Thread
    {
    	int bardelay = 100;    // to control speed of progress
    	JProgressBar pbr;
    	JFrame panel;

    	public control(JProgressBar defaulty)
    	{
    		 pbr=defaulty;
    	}

    	public void run()
    	{
    		int min = pbr.getMinimum();
    		int max = pbr.getMaximum();

    		Runnable runner = new Runnable()    // runnable class updates the thread
    		{
    			public void run()
    			{
                     int value = pbr.getValue();      // controls how large a portion of the bar is coverd by each step
                     pbr.setValue(value+1);
                }
            };

            for(int i=min; i            {
                try
                {
                    EventQueue.invokeAndWait(runner);
                    // Our job for each step is to just sleep
                    Thread.sleep(bardelay);

                }

                catch (InterruptedException ignoredException)
                 {}
                catch (InvocationTargetException ignoredException)
                 {}

                 if(i==max-1)
                 {
                 	bar.setVisible(false);
                 	JOptionPane.showMessageDialog(panel,"COMPLETE, THEN PRESS OK TO VIEW YOUR THE RECEIPT");
                 	bar.answer();
                 	setVisible(true);
                 }


            }
    	}


    }//end class
    /*******************************************
    	    END OF PROGRESSBAR CLASS
    ********************************************/

    public static void password() {
        JTextField userField = new JTextField(  );
        JPasswordField passField = new JPasswordField(  );
        String message = "Please Enter User Name and your Password.";
        String name="UserName:";
        String pswd="Password:";
        JOptionPane.showOptionDialog(null,
            new Object[] { message, name, userField,pswd, passField },
            "Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null, null, null);

        	JOptionPane.showMessageDialog(null, "thier is no Database found!.",
            "DataBaseManagement", JOptionPane.WARNING_MESSAGE);

    }

}



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wing_cafe;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class selectMenu extends JDialog implements ActionListener
	{
		//action listners
    	 public void actionPerformed(ActionEvent e)
    {
        String actionCommand = e.getActionCommand();

        if (actionCommand.equals("proceed"))
        {
            try
            {
                    if(recalcTotal()!=0){
                    	wing_cafe.appendList.addElement("Full Meal");
               	CafeCalculation.totalBalance( recalcTotal());
                dispose();
                    }
                   else
                   	throw  new Throwable();

            }
            //catch (exception ex)

            catch (Exception ex)
            {
               JOptionPane.showMessageDialog(null,"Error","Notice!",JOptionPane.ERROR_MESSAGE);
            }
            catch(Throwable b){
            	JOptionPane.showMessageDialog(null,"Please choose Menu and press ok OR cancel to exit!","Notice!",JOptionPane.ERROR_MESSAGE);
                        }
        }
        	else
        		if (actionCommand.equals("Cancel"))
        {
            try
            {
               dispose();


            }
            //catch (exception ex)

            catch (Exception ex)
            {
                JOptionPane.showMessageDialog(null,"Error","Notice!",JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //declaration of useful objects and classes

	protected JList m_list;
	protected JLabel m_total;
	JPanel buttons=new JPanel();
	//buttons
	    JButton jb1 = new JButton("Cancel");
		JButton jb2 = new JButton("OK!");


    /*******************************************
    	     CONSTRUCTOR STARTS HERE
    ********************************************/
			//constractor
			public selectMenu() {
			super();
			setTitle("Food List [Check boxes]");
			setModal(true);
			setSize(280, 300);
			getContentPane().setLayout(new FlowLayout());

			/* FOOD TO ADD ON SELECTION OPTIONS AND CORESPONDING PRICES*/
			FoodList[] options = {

					new FoodList("Supper (Rice and Chicken)", 40),
					new FoodList("Lunch (Papa and Chicken/stew)", 30),
					new FoodList("Burger and Coke 500ml", 60),
                                        new FoodList("Chips only", 10),
					new FoodList("Breakfast(Burns and Coffee)", 20),
					new FoodList("Other meals (chips and Chicken)", 50),
					new FoodList("Other meals (Papa and Linaoa)", 15),
					new FoodList("Other meals (Bread and Drink/cofee )", 25),
			                    };

			       //ADD TO CONSTRUCTOR THE FOLLOWING OBJECTS AND CLASSES
			m_list = new JList(options);
			CheckListCellRenderer renderer = new CheckListCellRenderer();
			m_list.setCellRenderer(renderer);
			m_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			CheckListener lst = new CheckListener(this);
			m_list.addMouseListener(lst);
			m_list.addKeyListener(lst);
			JScrollPane ps = new JScrollPane();
			ps.getViewport().add(m_list);
			m_total = new JLabel("Amount To Pay: M0.00");
			JPanel p = new JPanel();
			p.setLayout(new BorderLayout());
			p.add(ps, BorderLayout.CENTER);
			p.add(m_total, BorderLayout.SOUTH);
			p.setBorder(new TitledBorder(new EtchedBorder(),
			"Please select Food you want to order:") );
			getContentPane().add(p);
			//closing window
				WindowListener wndCloser = new WindowAdapter() {
				       public void windowClosing(WindowEvent e)
				            {
				                dispose();
				            }

				                                    };//end of windowsListner
				//add buttons panel to frame
				add(buttons);
				buttons.add(jb1);
				buttons.add(jb2);

			  jb1.addActionListener(this);
			  jb2.addActionListener(this);

		addWindowListener(wndCloser);
		setVisible(false);
		recalcTotal();

		                   }//end of constructor choose menu
				//calculate total of payment
		public Double recalcTotal() {
				ListModel model = m_list.getModel();
				Double total = 0.00;
				for (int k=0; k<model.getsize();>				FoodList data = (FoodList)model.getElementAt(k);
				if (data.isSelected())
				total += data.getSize();
				}
			m_total.setText("Amount To Pay: M"+total+"0");
			 return total;
			}



		}

		//check list class
		class CheckListCellRenderer extends JCheckBox
		implements ListCellRenderer
		{
		protected static Border m_noFocusBorder =
		new EmptyBorder(1, 1, 1, 1);
		public CheckListCellRenderer() {
		super();
		setOpaque(true);
		setBorder(m_noFocusBorder);
		}
		public Component getListCellRendererComponent(JList list,
		Object value, int index, boolean isSelected, boolean cellHasFocus)
		{
		setText(value.toString());
		setBackground(isSelected ? list.getSelectionBackground() :
		list.getBackground());
		setForeground(isSelected ? list.getSelectionForeground() :
		list.getForeground());
		FoodList data = (FoodList)value;
		setSelected(data.isSelected());
		setFont(list.getFont());
		setBorder((cellHasFocus) ?
		UIManager.getBorder("List.focusCellHighlightBorder")
		: m_noFocusBorder);
		return this;
		}
		}
		class CheckListener implements MouseListener, KeyListener
		{
		protected selectMenu m_parent;
		protected JList m_list;
		public CheckListener(selectMenu parent) {
		m_parent = parent;
		m_list = parent.m_list;
		}
		public void mouseClicked(MouseEvent e) {
		if (e.getX() < 20)
		doCheck();
		}
		public void mousePressed(MouseEvent e) {}
		public void mouseReleased(MouseEvent e) {}
		public void mouseEntered(MouseEvent e) {}
		public void mouseExited(MouseEvent e) {}

		public void keyPressed(KeyEvent e) {
		if (e.getKeyChar() == ' ')
		doCheck();
		}
		public void keyTyped(KeyEvent e) {}
		public void keyReleased(KeyEvent e) {}
		protected void doCheck() {
		int index = m_list.getSelectedIndex();
		if (index < 0)
		return;
		FoodList data = (FoodList)m_list.getModel().
		getElementAt(index);
		data.invertSelected();
		m_list.repaint();
		m_parent.recalcTotal();
		}
		}
		class FoodList
		{
		protected String m_name;
		protected int m_size;
		protected boolean m_selected;
		public FoodList(String name, int size) {
		m_name = name;
		m_size = size;
		m_selected = false;
		}
		public String getName() { return m_name; }
		public int getSize() { return m_size; }
		public void setSelected(boolean selected) {
		m_selected = selected;
		}
		public void invertSelected() { m_selected = !m_selected; }
		public boolean isSelected() { return m_selected; }
		public String toString() { return m_name+" =M"+m_size+".00"; }
}




/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wing_cafe;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
import java.lang.reflect.InvocationTargetException;
class Progressbar extends JDialog {

 private static String tag;
 public static JPanel panel = new JPanel();
 public static DefaultBoundedRangeModel model =new DefaultBoundedRangeModel(10,1,0,50);
 public static JProgressBar pbr=new JProgressBar(model);

   public Progressbar(){
   setLayout(new FlowLayout());
     setTitle("Printing the receipt");
   //progess seters
   pbr.setBorderPainted(true);
   pbr.setStringPainted(true);
   //colrs
   pbr.setFont(new Font("algerian",Font.BOLD,20));
   pbr.setForeground(Color.GREEN);

   setVisible(false);
   setSize(300,190);
   setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

   }
      //setTag orderNumber
      private static String setTag ()
    {   //4 upper case letters and 12
        Random gen = new Random ();
        tag = "";
        for (int i = 0; i < 4; i++)
        {
            int code = gen.nextInt (26)+ 65;
            tag += (char) code;
        }
        return tag;
     }

  //to be printed on OptionPane

	public static void answer( ){

	  String outPut = "\tTHIS IS YOUR ORDER RECEIPT\n"+
	                  ":::::::::::::::::::::::::::::::::::::"+
					  "::::::::::::::::::::::::::::::::::::::"+
					  "::::::::::::::::::::::::::::::::::::::::::::\n"/*+
	  "\nYour Oder was placed at"+wing_cafe.timeField.getText()+
	  "\nYour Order Tag Number is\t:"+setTag ()+"\nOdered Menu are\t:"+wing_cafe.appendList+
	  "\nTotal Amount(tax include) is\t:"+"M"+wing_cafe.orderTotalText.getText()+
	  "\nRecieved Cash\t\t:"+"M"+wing_cafe.amountText.getText()+".00"+
	  "\nChange is\t\t:"+"M"+wing_cafe.changeText.getText()*/;


           JTextArea content = new JTextArea();
           content.setText(outPut );
			  content.setBackground(Color.GREEN);
			  content.setForeground(Color.WHITE);
		      content.setEditable(false);
		   JOptionPane.showMessageDialog( null, content,
              "Order Slip", JOptionPane.PLAIN_MESSAGE );

	}

}


Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wing_cafe;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 *
 * @author rasta
 */
public class CafeCalculation
{
public Double amount;
Double tax=0.14;
public static double totalAmnt = 0.0;
public Double totalAmount = 0.0;

    public CafeCalculation() {
        super();
        }

    /******************************************************************
     ************OBJECTS HOLDING AVAILABLE FOOODS**********************/

      //BURGER STARTS
        public void burger(){
                    int quantity=0;
                    quantity=recievInt(quantity);
                    if(quantity>0){
                   amount=16.00;
                   amount=amount*quantity;
                   totalAmount+=amount;
                     wing_cafe.appendList.addElement("Burger x"+"["+quantity+"]");
                     totalBalance( totalAmount);
                        totalAmount=0.0;
                     }
                    }//ENDS

             //    DRINK STARTS

          public void Drinks(){
           int quantity=0;
                    quantity=recievInt(quantity);
                    if(quantity>0){
                   amount=8.00;
                   amount=amount*quantity;
                   totalAmount+=amount;
                     wing_cafe.appendList.addElement("Drink x"+"["+quantity+"]");
                     totalBalance( totalAmount);
                     totalAmount=0.0;
                             }
                           }//ENDS

                //  CHIPS STARTS
           public void Chips(){
            int quantity=0;
                    quantity=recievInt(quantity);
                     if(amount>0){
                   amount=10.00;
                   amount=amount*quantity;
                   totalAmount+=amount;
                     wing_cafe.appendList.addElement("Chips x"+"["+quantity+"]");
                     totalBalance( totalAmount);
                     totalAmount=0.0;
                        }
                     }//ENDS

             //   PIZZA STARTS
           public void Pizza(){
            int quantity=0;
                    quantity=recievInt(quantity);
                    if(quantity>0){
                   amount=20.00;
                   amount=amount*quantity;
                   totalAmount+=amount;
                   wing_cafe.appendList.addElement("Pizza x"+"["+quantity+"]");
                     totalBalance( totalAmount);
                     totalAmount=0.0;
                    }
                }//ENDS
                    // reciev quantity module
                     public static int recievInt(int Quantity){
                                try {

                                    Quantity=Integer.parseInt
                                   (JOptionPane.showInputDialog("Enter Quantity!"));

                                           if(Quantity<=0){
                                 throw new Throwable();
                                            }
                                   }
                            catch(NumberFormatException e){
                            JOptionPane.showMessageDialog(null, "Quantity are Integers Please (EXIT)", "Notice",JOptionPane.ERROR_MESSAGE);
                            }

                            catch(Throwable a){
                            JOptionPane.showMessageDialog(null, "Quanty is never 0 please (EXIT)", "Notice",JOptionPane.ERROR_MESSAGE);
                            }
                             return Quantity;

                             }

                         //total balance module to aapend on cafe frame
               public static void totalBalance( Double value){
                    totalAmnt += value;
                    wing_cafe.orderTotalText.setText(""+totalAmnt+"0");
                   }

}
Posted
Updated 6-Dec-13 2:07am
v2

1 solution

- make folder "resource" beside of "src"
- add folder "img" in there
- put images for buttons in "img"
- reference there.

- IMPORTANT: Make sure "resource" is included in build (project properties).

Please also see How to use icons - the Java Tutorials[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900