You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.7 KiB

package org.atm.view.gui;
import org.atm.model.Customer;
import org.atm.ctrl.Validate;
import org.atm.dao.Login;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Gui extends JFrame {
private JButton jButtonLogin;
private JLabel jLabelCid;
private JLabel jLabelCpin;
private JPanel jPanel;
private JPanel jPanelBtn;
private JPanel jPanelCid;
private JPanel jPanelCpin;
private JTextField jTextFieldCid;
private JPasswordField jTextFieldCpin;
public Gui() {
this.setTitle("GUI ATM MTE From EA For CS231");
this.setSize(300, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
jPanel = new JPanel(new GridLayout(3, 1));
jPanelCid = new JPanel();
jLabelCid = new JLabel("CID");
jLabelCid.setForeground(Color.RED);
jLabelCid.setFont(new Font("", Font.BOLD, 15));
jTextFieldCid = new JTextField(15);
jPanelCid.add(jLabelCid);
jPanelCid.add(jTextFieldCid);
jPanelCpin = new JPanel();
jLabelCpin = new JLabel("CPIN");
jLabelCpin.setForeground(Color.RED);
jLabelCpin.setFont(new Font("", Font.BOLD, 15));
jTextFieldCpin = new JPasswordField(15);
jPanelCpin.add(jLabelCpin);
jPanelCpin.add(jTextFieldCpin);
jPanelBtn = new JPanel();
jButtonLogin = new JButton("LOGIN");
jPanelBtn.add(jButtonLogin);
jPanel.add(jPanelCid);
jPanel.add(jPanelCpin);
jPanel.add(jPanelBtn);
this.add(jPanel);
this.setVisible(true);
jButtonLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cid = new String(jTextFieldCid.getText());
if (cid.length() <= 0) {
JOptionPane.showMessageDialog(null, "CID NULL");
System.out.println("CID NULL");
} else {
String cpin = new String(jTextFieldCpin.getPassword());
Customer inputCustomer = new Customer(cid, cpin);
Customer returnCustomer = null;
if (Validate.is7RandNumeric(cid) && Validate.is7RandNumeric(cpin))
returnCustomer = new Login().login(inputCustomer);
if (returnCustomer != null) {
JOptionPane.showMessageDialog(null, "LOGIN SUCCEEDED!", "PROMPT",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "ID OR PIN ERROR!", "PROMPT",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
}
public static void main(String[] args) {
new Gui();
}
}// end Gui