0

这是我的登录类:

        package mangInasal;

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

    public class MILogin extends JFrame {

        private JLabel lblUsername, lblPassword;
        private JTextField txtUsername;
        private JPasswordField txtPassword;
        private JButton btnLogin, btnCancel;

        public MILogin() {

            super("Login");
            setLayout(new FlowLayout());

            lblUsername = new JLabel("Username: ");
            add(lblUsername);

            txtUsername = new JTextField(10);
            add(txtUsername);

            lblPassword = new JLabel("Password: ");
            add(lblPassword);

            txtPassword = new JPasswordField(10);
            add(txtPassword);

            btnLogin = new JButton("Login");
            add(btnLogin);

            btnCancel = new JButton("Cancel");
            add(btnCancel);

            ActionListener listener = new ButtonListener();
            btnLogin.addActionListener(listener);
            btnCancel.addActionListener(listener);

        }

        private class ButtonListener implements ActionListener {

            public void actionPerformed(ActionEvent e) {

                JButton source = (JButton) e.getSource();
                String username = txtUsername.getText().toUpperCase();
                String pass = txtPassword.getText();

                if (source == btnLogin) {

                    if (username.equals("TIPQC") && (pass.equals("ABET"))) {
                        String okay = "defimages/loginsuccess.gif";
                        java.net.URL imgURL = getClass().getClassLoader().getResource(okay);
                        ImageIcon okpic = new ImageIcon(imgURL);
                        JOptionPane.showMessageDialog(null, "WELCOME", "Correct Input", JOptionPane.PLAIN_MESSAGE, okpic);
                        dispose();
                        mangInasaldef manginasaldef = new mangInasaldef();
                        manginasaldef.run();

                    } else {
                        String okay = "defimages/loginfail.gif";
                        java.net.URL imgURL = getClass().getClassLoader().getResource(okay);
                        ImageIcon failpic = new ImageIcon(imgURL);
                        JOptionPane.showMessageDialog(null, "Incorrect Username or Password", "Message Dialog", JOptionPane.PLAIN_MESSAGE, failpic);
                    }

                }

                if (source == btnCancel) {

                    System.exit(1);
                }
            }
        }

        public void run() {

            setSize(200, 200);
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setResizable(false);



        }

        public static void main(String[] args) {

            MILogin milogin = new MILogin();
            milogin.run();

        }
    }

这是我的主要课程:

    package mangInasal;

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class mangInasaldef  extends JFrame{ //class name

      private static String username  = "";
      private static String customername  = "";
      private static String dineOut  = "";
      private String order = "";
      private String order1 = "";
      private String order2 = "";
      private String order3 = "";
      private String order4 = "";
      private String order5 = "";
      private String order6 = "";
      private String order7 = "";
      private String order8 = "";
      private String order9 = "";
      private String order10 = "";
      private String order11 = "";
      private String order12 = "";
      private String order13 = "";
      private String order14 = "";
      private String order15 = "";
      private String order16 = "";
      private String order17 = "";
       private int total = 0;
       private int totalSpicy = 0; 
       private int total1 = 0;
        private int total2= 0;
        private int total3 = 0;
        private int total4 = 0;
        private int total5 = 0;
        private int total6 = 0;
        private int total7 = 0;
        private int total8 = 0;
        private int total9 = 0;
        private int total10 = 0;
        private int total11 = 0;
        private int total12 = 0;
        private int total13 = 0;
        private int total14 = 0;
        private int total15 = 0;
        private int total16 = 0;
        private int total17 = 0;
      private int totalOrder = total + totalSpicy + total1 + total2 + total3 + total4 + total5 + total6 + total7 + total8 + total9 + total10 + total11 + total12 + total13 + total14 + total15;
      private double vatCollected = totalOrder * 0.12;
      private boolean exact = true; // a boolean variable that is declared private in order to be accessed by different methods
      private double change, cashTendered;
      private static int cashAmount;
      private static Scanner inp = new Scanner(System.in); // private static declared Scanner which allows the user to input characters or strings by different methods
      private JLabel lblUsername, lblPassword;
    private JTextField txtUsername;
    private JPasswordField txtPassword;
    private JButton btnLogin, btnCancel;



public mangInasaldef() {

      boolean repeatLoop = true;

        System.out.print("\nInput Customer Name: ");
        String customerName = inp.nextLine();
        customername = customerName;
        System.out.print("\nInput Cashier Name: ");
        String user = inp.nextLine();
        username = user;
     do{
        System.out.print("\nInput either Dine In or Take Out: ");
        String dInDOut = inp.nextLine();
        dineOut = dInDOut;
            if (dineOut.equals("Dine In") || dineOut.equals("Take Out")){
             System.out.print("");
             repeatLoop = false;
             }
            else{
             JOptionPane.showMessageDialog(null, "Try again! Please input Dine In or Take Out only!","Error", JOptionPane.ERROR_MESSAGE);
                 repeatLoop = true;
                 System.out.print ("\f");
                }
     }while(repeatLoop);

        System.out.print("\n\n\t\tCashier: " +username);
        System.out.print("                          "+dineOut);
        System.out.print("\n\t\tCustomer Name: " +customername);


    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run()
        {
            new mangInasaldef();
        }
    });
}

public mangInasaldef() {

    JFrame frame = new JFrame("Mang Inasal Ordering System");
    JPanel panel = new JPanel();
    String choices[] = {"Paborito Meal 1 Paa","Paborito Meal 1.5 (Spicy Paa with Thigh part)","Paborito Meal 2 (Pecho)","Paborito Meal 3 (Pork Barbeque 4 pcs)","Paborito Meal 4 (Bangus Sisig)","Paborito Meal 5 (Pork Sisig)","Paborito Meal 6 (Bangus Inihaw)","Sulit Meal 1 (Paa)","Sulit Meal 2 (Pork Barbeque 2 pcs)","Pancit Bihon","Dinuguan at Puto","Ensaladang Talong","Softdrinks","Iced Tea","HaloHalo","Leche Flan","Turon Split","Print Receipt"};
    JComboBox combo = new JComboBox(choices);
    combo.setBackground(Color.black);
    combo.setForeground(Color.yellow);
    panel.add(combo);
    frame.add(panel); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(350,100);
    frame.setVisible(true);


    combo.addItemListener(new ItemListener () {
        @Override
        public void itemStateChanged(ItemEvent e)
        {
            String item = (String)e.getItem();
            if (e.getStateChange () == ItemEvent.SELECTED)
            {
                System.out.print("\nYou chose " +item);
                    if (item.equals("Paborito Meal 1 Paa"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM1");

                        Integer bilang= Integer.valueOf((String)val);
                        total = bilang * 99;
                        order =  " " + bilang + " " + " PM1 PAA W/ RICE" +"                     "+ total + ".00V" + "\n"; //stores the values of the variables bilang and total in the variable order and prints them

                    }
                     if (item.equals("Paborito Meal 1.5 (Spicy Paa with Thigh part)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM1.5"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        totalSpicy = bilang * 99;
                        order1 =  " " + bilang + " " + " PM1.5 PAA" +"                           "+ totalSpicy + ".00V" + "\n"; //stores the values of the variables bilang and total in the variable order and prints them

                    }
                    if (item.equals("Paborito Meal 2 (Pecho)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM2"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total1 = bilang * 99;
                        order2 =  " " + bilang + " " + " PM2 PECHO W/ RICE" +"                   "+ total1 + ".00V" + "\n";

                    }
                    if (item.equals("Paborito Meal 3 (Pork Barbeque 4 pcs)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM3"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total2 = bilang * 99;
                        order3 =  " " + bilang + " " + " PM3 PORK BBQ W/ RICE " +"               "+ total2 + ".00V" + "\n";

                    }
                    if (item.equals("Paborito Meal 4 (Bangus Sisig)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM4"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total3 = bilang * 99;
                        order4 =  " " + bilang + " " + " PM4 BANGUS SISIG " +"                   "+ total3 + ".00V" + "\n";

                    }
                    if (item.equals("Paborito Meal 5 (Pork Sisig)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM5"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total4 = bilang * 99;
                        order5 =  " " + bilang + " " + " PM5 PORK SISIG " +"                     "+ total4 + ".00V" + "\n";

                    }
                    if (item.equals("Paborito Meal 6 (Bangus Inihaw)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of PM6"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total5 = bilang * 99;
                        order6 =  " " + bilang + " " + " PM6 BANGUS INIHAW " +"                  "+ total5 + ".00V" + "\n";

                    }
                    if (item.equals("Sulit Meal 1 (Paa)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of SM1"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total6 = bilang * 59;
                        order7 =  " " + bilang + " " + " SM1 PAA " +"                            "+ total6 + ".00V" + "\n";

                    }
                    if (item.equals("Sulit Meal 2 (Pork Barbeque 2 pcs)"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of SM2"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total7 = bilang * 59;
                        order8 =  " " + bilang + " " + " SM2 PORK BBQ 2 " +"                     "+ total7 + ".00V" + "\n";

                    }
                    if (item.equals("Pancit Bihon"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Pancit Bihon"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total8 = bilang * 49;
                        order9 =  " " + bilang + " " + " Pancit Bihon " +"                       "+ total8 + ".00V" + "\n";

                    }
                    if (item.equals("Dinuguan at Puto"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Dinuguan"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total9 = bilang * 49;
                        order10 =  " " + bilang + " " + " Dinuguan at Puto " +"                   "+ total9 + ".00V" + "\n";

                    }
                    if (item.equals("Ensaladang Talong"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Ensaladang Talong"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total10 = bilang * 29;
                        order12 =  " " + bilang + " " + " Ensaladang Talong " +"                  "+ total10 + ".00V" + "\n";

                    }
                    if (item.equals("Softdrinks"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Softdrinks"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total11 = bilang * 25;
                        order13 =  " " + bilang + " " + " Softdrinks " +"                         "+ total11 + ".00V" + "\n";

                    }
                    if (item.equals("Iced Tea"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Iced Tea"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total12 = bilang * 25;
                        order14 =  " " + bilang + " " + " Iced Tea " +"                           "+ total12 + ".00V" + "\n";

                    }
                    if (item.equals("HaloHalo"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of HaloHalo"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total13 = bilang * 49;
                        order15 =  " " + bilang + " " + " HaloHalo " +"                           "+ total13 + ".00V" + "\n";

                    }
                    if (item.equals("Leche Flan"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Leche Flan"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total14 = bilang * 29;
                        order16 =  " " + bilang + " " + " Leche Flan " +"                         "+ total14 + ".00V" + "\n";

                    }
                    if (item.equals("Turon Split"))
                    {
            Object val = JOptionPane.showInputDialog("Please input quantity of Turon Split"); 
            System.out.print(val);

                        Integer bilang= Integer.valueOf((String)val);
                        total15 = bilang * 39;
                        order17 =  " " + bilang + " " + " Turon Split " +"                        "+ total15 + ".00V";

                    }
                    if (item.equals("Print Receipt")) // if Print Receipt was selected it will go to the method computeReceipt
                    {
                        System.out.print("\f"); // clears the screen
                        computeReceipt();
                    }


            }
    }
    });
    }

    public void computeReceipt() {
        totalOrder = total + totalSpicy + total1 + total2 + total3 + total4 + total5 + total6 + total7 + total8 + total9 + total10 + total11 + total12 + total13 + total14 + total15;
        vatCollected = totalOrder * 0.12;
        exact = true;

        do{ 
        System.out.print("\n\n\tYour total bill is: "+totalOrder);
        exact = false;

        Object cashMo = JOptionPane.showInputDialog("Please input here your cash");
            System.out.println(cashMo);
                        cashAmount = Integer.valueOf((String)cashMo);
        exact = false;
        change = cashAmount - totalOrder;
            if (cashAmount < totalOrder) {
                JOptionPane.showMessageDialog(null, "Try again. Please enter sufficient money to proceed.","Invalid Input", JOptionPane.ERROR_MESSAGE);   
            exact = true; 
            }
        }while(exact);
        System.out.print("\f");
        etoPoeReceipt();
    }


    public void etoPoeReceipt() {
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
        Date date = new Date(); 


        System.out.print("\n                 MANG INASAL");
        System.out.print("\n             BLUMENTRITT BRANCH");
        System.out.print("\n         #1631-1633 BLUMENTRITT ST.,");
        System.out.print("\n            STA CRUZ. MANILA 0000");
        System.out.print("\n               (932) 885-5844");
        System.out.print("\n             Operated by: R L YU");
        System.out.print("\n             TIN 202-161-017-000 VAT");
        System.out.print("\n         ACC. NO.: 050-204079836-000019");
        System.out.print("\n             Tel. #: (02)493-6801");
        System.out.print("\n\n Cashier: " +username);
        System.out.print("                    STATION: 2");
        System.out.print("\n ---------------------------------------------");
        System.out.print("\n O.R #: 84486");
        System.out.print("                          "+dineOut);
        System.out.print("\n Customer Name: " +customername);
        System.out.print("                       24");
        System.out.print("\n ---------------------------------------------");
        System.out.print("\n                   >>SETTLED<<\n");
        System.out.print(""+order );
        System.out.print(""+order1 );
        System.out.print(""+order2 );
        System.out.print(""+order3 );
        System.out.print(""+order4 );
        System.out.print(""+order5 );
        System.out.print(""+order6 );
        System.out.print(""+order7 );
        System.out.print(""+order8 );
        System.out.print(""+order9 );
        System.out.print(""+order10 );
        System.out.print(""+order11 );
        System.out.print(""+order12 );
        System.out.print(""+order13 );
        System.out.print(""+order14 );
        System.out.print(""+order15 );
        System.out.print(""+order16 );
        System.out.print(""+order17 );
        System.out.print("\n\n SUB TOTAL:                             "+totalOrder+ ".00");
        System.out.print("\n DELIVERY VAT:                            0.00");
        System.out.print("\n                                        ======");
        System.out.print("\n AMOUNT DUE:                            "+totalOrder+ ".00\n\n");
        System.out.printf(" VAT COLLECTED                          %.2f",vatCollected); // declares that the variable should be in two decimal places. % is called format specifier and f is the converter
        System.out.println("");
        System.out.print(" CASH Tendered:                         "+cashAmount+ ".00");
        System.out.print("\n                                        ======");
        System.out.printf("\n CHANGE:                                %.2f",change);
        System.out.print("\n               >>Ticket #: 62<<");
        System.out.print("\n       Created:  ");
        System.out.print(dateFormat.format(date));
        System.out.print("\n       SETTLED:  ");
        System.out.print(dateFormat.format(date));
        System.out.print("\n\n *********************************************");
        System.out.print("\n THIS SERVES AS AN OFFICIAL RECEIPT.");
        System.out.print("\n\n For Feedback: TEXT MIO467(Comments/ Suggest");
        System.out.print("\n ions)  and  SEND  to  0917-5941111 or CALL US");
        System.out.print("\n at 0917-5596258");
        System.out.print("\n Email: feedback@manginasal.com");
        System.out.print("\n\n      THANK YOU FOR DINING WITH US!");
        System.out.print("\n\n *********************************************");
        System.out.print("\n S/N: 120416ASL03/1105-6105-9230");
        System.out.print("\n DT S/N: 41-L6971 (P0S1)");
        System.out.print("\n PERMIT NO: 0412-031-125295-000");
        System.out.print("\n MIN: 120276752");

    }





}

登录类成功访问后,不再继续main方法。我不知道需要操作哪些代码才能将登录类连接到主类。感谢那些愿意提供帮助的人!:)

4

1 回答 1

0

从登录类中删除主要方法:

public static void main(String[] args) {

            MILogin milogin = new MILogin();
            milogin.run();

}

然后从您的主类中实例化 MILogin 类:

MILogin milogin = new MILogin();
milogin.run();
于 2013-10-11T14:21:42.900 回答