Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class CreateAccount extends JFrame{
- private JLabel user, pass; //label next to username and password field
- private JTextField username; //enter username
- private JPasswordField password; //enter password
- private JButton create;
- private String u, p;
- private static final int WIDTH = 500;
- private static final int HEIGHT = 300;
- public CreateAccount(){
- setTitle("Create Account");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(WIDTH, HEIGHT);
- setMinimumSize(new Dimension(WIDTH, HEIGHT));
- setLocationRelativeTo(null);
- setResizable(false);
- createView();
- setVisible(true);
- }
- private void createView(){
- JPanel panelMain = new JPanel(null);
- getContentPane().add(panelMain);
- user = new JLabel("Username: ");
- panelMain.add(user);
- user.setBounds(50, 30, 120, 25);
- username = new JTextField();
- panelMain.add(username);
- username.setBounds(140, 30, 150, 25);
- pass = new JLabel("Password: ");
- panelMain.add(pass);
- pass.setBounds(50, 100, 120, 25);
- password = new JPasswordField();
- panelMain.add(password);
- password.setBounds(140, 100, 150, 25);
- create = new JButton("Create");
- panelMain.add(create);
- create.setBounds(170, 180, 100,25);
- create.addActionListener((new Listener()));
- }
- private class Listener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- String usn = username.getText();
- String psd = password.getText();
- setUser(usn);
- setPass(psd);
- new Login();
- setVisible(false);
- }
- }
- public void setUser(String usn){
- this.u = usn;
- }
- public String getUser(){
- return u;
- }
- public void setPass(String psd){
- this.p = psd;
- }
- public String getPass(){
- return p;
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Login extends JFrame{
- private JLabel user, pass;
- private JTextField username;
- JPasswordField password;
- private JButton login;
- private static final int WIDTH = 500;
- private static final int HEIGHT = 300;
- public Login(){
- setTitle("Login");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(WIDTH, HEIGHT);
- setMinimumSize(new Dimension(400, 200));
- setLocationRelativeTo(null);
- setResizable(false);
- createView();
- setVisible(true);
- }
- private void createView(){
- JPanel panel = new JPanel(null);
- getContentPane().add(panel);
- user = new JLabel("Username: ");
- panel.add(user);
- user.setBounds(50, 30, 120, 25);
- username = new JTextField();
- panel.add(username);
- username.setBounds(140, 30, 150, 25);
- pass = new JLabel("Password: ");
- panel.add(pass);
- pass.setBounds(50, 100, 120, 25);
- password = new JPasswordField();
- panel.add(password);
- password.setBounds(140, 100, 150, 25);
- login = new JButton("Login");
- panel.add(login);
- login.setBounds(170, 170, 100, 25);
- login.addActionListener((new Listener()));
- }
- private class Listener implements ActionListener{
- CreateAccount grab = new CreateAccount();
- @Override
- public void actionPerformed(ActionEvent e) {
- String usn = username.getText();
- String psd = password.getText();
- if(usn.equals("Admin") && psd.equals("Password")){
- new AdminDB();
- }
- else if (usn.equals(grab.getUser()) && psd.equals(grab.getPass()))
- {
- new UserDB();
- }
- else
- {
- JOptionPane.showMessageDialog(null,"Invalid login info, try again");
- }
- setVisible(false);
- }
- }
- }
Add Comment
Please, Sign In to add comment