OrderingSystem.java
上传用户:huitongad
上传日期:2022-06-08
资源大小:2k
文件大小:7k
- import java.awt.*; //libraries
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.border.*;
- import javax.swing.ImageIcon.*;
- public class OrderingSystem extends JFrame implements ActionListener
- { //frame with actionlistner
- JButton b1 = new JButton("Alfredo"); //buttons
- JButton b2 = new JButton("Canalonie");
- JButton b3 = new JButton("Chicken noodles");
- JButton b4 = new JButton("Lazangia");
- JButton b5 = new JButton("4 season");
- JButton b6 = new JButton("Blabla");
- JButton b7 = new JButton("Salad");
- JButton b8 = new JButton("Mineral Water");
- JButton b9 = new JButton("Total");
- JButton b10 = new JButton("Close");
- JButton b11 = new JButton("Reset");
- //------------------------------------------------------------
- JLabel l1 = new JLabel("Ordering System");
- JLabel l2 = new JLabel("Reciept :");
- //--------------------------------------------------------------------
- JTextField t1 = new JTextField("0"); //textfields
- JTextField t2 = new JTextField("0");
- JTextField t3 = new JTextField("0");
- JTextField t4 = new JTextField("0");
- JTextField t5 = new JTextField("0");
- JTextField t6 = new JTextField("0");
- JTextField t7 = new JTextField("0");
- JTextField t8 = new JTextField("0");
- //---------------------------------------------------------------------
- JTextArea count=new JTextArea(37,20);
- JScrollPane scrol = new JScrollPane(count);
- double total=0.0;
- int Orderno=1;
- String Reciept ="order #"+Orderno+":n";
- //----------------------------------------------------------------
- OrderingSystem()
- {
- getContentPane().setLayout(new BorderLayout()); //GUI Layout
- l1.setForeground(Color.red);
- l1.setFont(new Font("Arial Black",Font.BOLD+Font.ITALIC,36));
- JPanel p1 = new JPanel();
- p1.add(l1);
- p1.setBackground(Color.black);
- getContentPane().add("North",p1);
- //---------------------------------------
- JPanel p2 = new JPanel();
- p2.setBackground(Color.black);
- b9.setBackground(Color.black);
- b11.setBackground(Color.black);
- b10.setBackground(Color.black);
- b9.setForeground(Color.red);
- b11.setForeground(Color.red);
- b10.setForeground(Color.red);
- b9.setFont(new Font("Courier New",Font.BOLD,18));
- b11.setFont(new Font("Courier New",Font.BOLD,18));
- b10.setFont(new Font("Courier New",Font.BOLD,18));
- p2.add(b9);
- p2.add(b11);
- p2.add(b10);
- getContentPane().add("South",p2);
- //-----------------------------text area in east----------------------------
- JPanel p3 = new JPanel();
- p3.setBorder(new TitledBorder("Reciept :"));
- p3.setLayout(new FlowLayout());
- p3.add(scrol);
- count.setEditable(false);
- getContentPane().add("East",p3);
- //----------------------------buttons and text fields-------------------------------
- JPanel p4 = new JPanel();
- p4.setBorder(new TitledBorder("Menu :"));
- p4.setLayout(new GridLayout(4,2));
- p4.add(b1);
- p4.add(t1);
- p4.add(b2);
- p4.add(t2);
- p4.add(b3);
- p4.add(t3);
- p4.add(b4);
- p4.add(t4);
- p4.add(b5);
- p4.add(t5);
- p4.add(b6);
- p4.add(t6);
- p4.add(b7);
- p4.add(t7);
- p4.add(b8);
- p4.add(t8);
- getContentPane().add("West",p4);
- //----------------------------------------------------------
- b1.addActionListener(this); //Listening to the buttons
- b2.addActionListener(this);
- b3.addActionListener(this);
- b4.addActionListener(this);
- b5.addActionListener(this);
- b6.addActionListener(this);
- b7.addActionListener(this);
- b8.addActionListener(this);
- b9.addActionListener(this);
- b10.addActionListener(this);
- b11.addActionListener(this);
- }
- public void actionPerformed (ActionEvent e)
- { //actionperformed
- String s;
- int x;
- if (e.getSource() == b1){
- s=t1.getText();
- x= Integer.parseInt(s);
- x++;
- t1.setText(x+"");
- Reciept += "Alfredo : 25 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b2){
- s=t2.getText();
- x= Integer.parseInt(s);
- x++;
- t2.setText(x+"");
- Reciept += "Canalonie : 35 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b3){
- s=t3.getText();
- x= Integer.parseInt(s);
- x++;
- t3.setText(x+"");
- Reciept += "Chicken noodles : 20 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b4){
- s=t4.getText();
- x= Integer.parseInt(s);
- x++;
- t4.setText(x+"");
- Reciept += "Lazangia : 30 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b5){
- s=t5.getText();
- x= Integer.parseInt(s);
- x++;
- t5.setText(x+"");
- Reciept += "4 season : 25 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b6){
- s=t6.getText();
- x= Integer.parseInt(s);
- x++;
- t6.setText(x+"");
- Reciept += "Blabla : 25 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b7){
- s=t7.getText();
- x= Integer.parseInt(s);
- x++;
- t7.setText(x+"");
- Reciept += "Salad : 12 LEn";
- count.setText(Reciept);
- }
- else if (e.getSource() == b8){
- s=t8.getText();
- x= Integer.parseInt(s);
- x++;
- t8.setText(x+"");
- Reciept += "Mineral Water : 5 LEn";
- count.setText(Reciept);
- }
- else if(e.getSource() == b9){ //calculating subtotal
- String a=t1.getText();
- String b=t2.getText();
- String c=t3.getText();
- String d=t4.getText();
- String ee=t5.getText();
- String f=t6.getText();
- String g=t7.getText();
- String h=t8.getText();
- double i=Double.parseDouble(a);
- i= i * 25;
- double j=Double.parseDouble(b);
- j= j * 35;
- double k=Double.parseDouble(c);
- k= k * 20;
- double l=Double.parseDouble(d);
- l= l * 30;
- double m=Double.parseDouble(ee);
- m= m * 25;
- double n=Double.parseDouble(f);
- n= n * 25;
- double o=Double.parseDouble(g);
- o= o * 12;
- double p=Double.parseDouble(h);
- p= p * 5;
- double z = (i+j+k+l+m+n+o+p);
- String y =z + "";
- String t=Reciept+"Total : "+z+"LE";
- count.setText(t);
- JOptionPane.showMessageDialog(null,"The total price is"+" "+ y+"LE", "Total",JOptionPane.PLAIN_MESSAGE);
- }
- //displaying subtotal
- else if (e.getSource() == b10){
- System.exit(0); //Exit the program
- }
- else if (e.getSource() == b11){ // reset all textfields
- t1.setText("0");
- t2.setText("0");
- t3.setText("0");
- t4.setText("0");
- t5.setText("0");
- t6.setText("0");
- t7.setText("0");
- t8.setText("0");
- count.setText("");
- Orderno++;
- Reciept ="order #"+Orderno+":n";
- }
- }
- public static void main (String[] a) { //main
- OrderingSystem OS = new OrderingSystem();
- OS.setSize(775,600);
- OS.setTitle("Food Court Ordering System");
- OS.setVisible(true);
- OS.setResizable(false);
- // Get the dimension of the screen
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int screenWidth = screenSize.width;
- int screenHeight = screenSize.height;
- // Get the dimension of the frame
- Dimension frameSize = OS.getSize();
- int x = (screenWidth - frameSize.width)/2;
- int y = (screenHeight - frameSize.height)/2;
- OS.setLocation(x,y);
- }
- }