Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.emrebank.bank;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- public class Login extends JFrame {
- public static String directory = System.getProperty("user.dir");
- public static File accounts = new File(directory + "/" + "accounts.txt");
- public static FileManagement filemanage = new FileManagement();
- public Login() {
- setTitle("Bank Login");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(890,490);
- getContentPane().setLayout(null);
- JLabel label = new JLabel("Login & Register");
- label.setFont(new Font("Lucida Grande", Font.PLAIN, 50));
- label.setHorizontalAlignment(SwingConstants.CENTER);
- label.setBounds(246, 6, 398, 96);
- getContentPane().add(label);
- user = new JTextField();
- user.setBounds(380, 130, 130, 26);
- getContentPane().add(user);
- user.setColumns(10);
- label_1 = new JLabel("Name:");
- label_1.setHorizontalAlignment(SwingConstants.CENTER);
- label_1.setBounds(328, 135, 50, 16);
- getContentPane().add(label_1);
- label_2 = new JLabel("Password:");
- label_2.setBounds(315, 178, 63, 16);
- getContentPane().add(label_2);
- btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- name = user.getText();
- pass = new String(password.getPassword());
- }
- });
- btnLogin.setBounds(198, 272, 117, 29);
- getContentPane().add(btnLogin);
- btnRegister = new JButton("Register");
- btnRegister.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- name = user.getText();
- pass = new String(password.getPassword());
- System.out.println(directory);
- filemanage.appendToFile(accounts, name + "\n" + pass);
- JOptionPane.showMessageDialog(null,
- "Created account with no errors. Please login with your new acount.");
- }
- });
- btnRegister.setBounds(527, 272, 117, 29);
- getContentPane().add(btnRegister);
- password = new JPasswordField();
- password.setEchoChar('*');
- password.setBounds(380, 173, 130, 26);
- getContentPane().add(password);
- message = new JOptionPane();
- getContentPane().add(message);
- setVisible(true);
- }
- private static final long serialVersionUID = 1L;
- private JTextField user;
- private JLabel label_1;
- private JLabel label_2;
- private JButton btnLogin;
- private JButton btnRegister;
- private JPasswordField password;
- public static JOptionPane message;
- public static String name;
- public static String pass;
- //@SuppressWarnings("static-access")
- public static void main(String[] args) {
- /*Bank bank = new Bank();
- while (true) {
- bank.lblName.setText(Bank.Name + ": $" + Bank.Money);
- if (bank.Money != 0) {
- bank.moneyInput.setEditable(false);
- } else {
- bank.moneyInput.setEditable(true);
- }
- }*/
- if (!accounts.exists())
- filemanage.createFile(accounts);
- new Login();
- }
- }
Add Comment
Please, Sign In to add comment