Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CardGame;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import java.awt.CardLayout;
- import javax.swing.JPanel;
- import java.awt.Color;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.Font;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- /**
- * This class contains the GUI for the blackjack game for first prototype
- * future iterations will be split up into classes and functions as discussed.
- *
- * @Author Lois Holman and Alex Davenport
- *
- * @version 2017-03-06
- *
- */
- public class GameGUI {
- private JFrame frame;
- private JTextField loginField;
- private JPasswordField passwordField;
- private JTextField firstnameField;
- private JTextField lastnameField;
- private JTextField usernameField;
- private JTextField emailField;
- private JPasswordField createpasswordField;
- private JPasswordField conpasswordField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- GameGUI window = new GameGUI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public GameGUI() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(new CardLayout(0, 0));
- final JPanel loginPanel = new JPanel();
- loginPanel.setBackground(new Color(0, 100, 0));
- frame.getContentPane().add(loginPanel, "name_260916078888005");
- loginPanel.setLayout(null);
- final JPanel createAccountPanel = new JPanel();
- createAccountPanel.setForeground(new Color(255, 255, 255));
- createAccountPanel.setBackground(new Color(0, 100, 0));
- frame.getContentPane().add(createAccountPanel, "name_260954822097931");
- createAccountPanel.setLayout(null);
- loginField = new JTextField();
- loginField.setBounds(217, 79, 130, 26);
- loginPanel.add(loginField);
- loginField.setColumns(10);
- passwordField = new JPasswordField();
- passwordField.setBounds(217, 134, 130, 26);
- loginPanel.add(passwordField);
- JLabel lblLogin = new JLabel("Login");
- lblLogin.setForeground(new Color(255, 255, 255));
- lblLogin.setBounds(50, 79, 61, 16);
- loginPanel.add(lblLogin);
- JLabel lblPassword = new JLabel("Password");
- lblPassword.setForeground(new Color(255, 255, 255));
- lblPassword.setBounds(50, 139, 61, 16);
- loginPanel.add(lblPassword);
- JLabel lblWhereDreamsAre = new JLabel("Where dreams are made <3.... </3");
- lblWhereDreamsAre.setForeground(new Color(255, 255, 255));
- lblWhereDreamsAre.setBounds(25, 6, 232, 16);
- loginPanel.add(lblWhereDreamsAre);
- firstnameField = new JTextField();
- firstnameField.setBounds(225, 34, 130, 26);
- createAccountPanel.add(firstnameField);
- firstnameField.setColumns(10);
- JLabel lblCreateAccount = new JLabel("Create Account");
- lblCreateAccount.setForeground(new Color(255, 255, 255));
- lblCreateAccount.setBounds(133, 6, 130, 16);
- createAccountPanel.add(lblCreateAccount);
- JLabel lblFirstName = new JLabel("First Name");
- lblFirstName.setForeground(new Color(255, 255, 255));
- lblFirstName.setBounds(45, 39, 112, 16);
- createAccountPanel.add(lblFirstName);
- JLabel lblLastName = new JLabel("Last Name\n");
- lblLastName.setForeground(new Color(255, 255, 255));
- lblLastName.setBounds(45, 82, 112, 16);
- createAccountPanel.add(lblLastName);
- JLabel lblUsername = new JLabel("Username (must be unique)\n");
- lblUsername.setForeground(new Color(255, 255, 255));
- lblUsername.setBounds(45, 110, 185, 16);
- createAccountPanel.add(lblUsername);
- JLabel lblEmailAddress = new JLabel("Email Address\n");
- lblEmailAddress.setForeground(new Color(255, 255, 255));
- lblEmailAddress.setBounds(45, 143, 112, 16);
- createAccountPanel.add(lblEmailAddress);
- JLabel lblPassword_1 = new JLabel("Password\n");
- lblPassword_1.setForeground(new Color(255, 255, 255));
- lblPassword_1.setBounds(45, 171, 112, 16);
- createAccountPanel.add(lblPassword_1);
- lastnameField = new JTextField();
- lastnameField.setBounds(225, 77, 130, 26);
- createAccountPanel.add(lastnameField);
- lastnameField.setColumns(10);
- usernameField = new JTextField();
- usernameField.setBounds(225, 105, 130, 26);
- createAccountPanel.add(usernameField);
- usernameField.setColumns(10);
- emailField = new JTextField();
- emailField.setBounds(225, 138, 130, 26);
- createAccountPanel.add(emailField);
- emailField.setColumns(10);
- JLabel lblConfirmPassword = new JLabel("Confirm Password\n");
- lblConfirmPassword.setForeground(new Color(255, 255, 255));
- lblConfirmPassword.setBounds(45, 199, 138, 16);
- createAccountPanel.add(lblConfirmPassword);
- createpasswordField = new JPasswordField();
- createpasswordField.setBounds(225, 166, 130, 26);
- createAccountPanel.add(createpasswordField);
- conpasswordField = new JPasswordField();
- conpasswordField.setBounds(225, 194, 130, 26);
- createAccountPanel.add(conpasswordField);
- final JPanel homePanel = new JPanel();
- homePanel.setBackground(new Color(0, 100, 0));
- frame.getContentPane().add(homePanel, "name_260958193000997");
- homePanel.setLayout(null);
- JLabel lblHomepageWelcome = new JLabel("Homepage Welcome!");
- lblHomepageWelcome.setForeground(new Color(255, 255, 255));
- lblHomepageWelcome.setBounds(23, 6, 188, 16);
- homePanel.add(lblHomepageWelcome);
- JButton btnLogout = new JButton("Logout");
- btnLogout.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- homePanel.setVisible(false);
- loginPanel.setVisible(true);
- }
- });
- btnLogout.setBounds(291, 221, 117, 29);
- homePanel.add(btnLogout);
- JButton btnCreateNewUser = new JButton("Create new user");
- btnCreateNewUser.addActionListener(new ActionListener() {
- //check for email match as well
- // googlr this
- @SuppressWarnings("deprecation")
- public void actionPerformed(ActionEvent e) {
- if (!functionDB.isUserRegistered(usernameField.getText())){
- if(conpasswordField.getText() == createpasswordField.getText()){
- functionDB.insertUserIntoDatabase(new User(usernameField.getText(),createpasswordField.getText(),firstnameField.getText(),lastnameField.getText(), emailField.getText())); //add email
- createAccountPanel.setVisible(false);
- homePanel.setVisible(true);
- }
- }
- // query for username and email unique then allow it and save to DB etc
- }
- });
- btnCreateNewUser.setBounds(133, 231, 175, 29);
- createAccountPanel.add(btnCreateNewUser);
- JButton btnBack = new JButton("Back");
- btnBack.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- createAccountPanel.setVisible(false);
- loginPanel.setVisible(true);
- }
- });
- btnBack.setBounds(6, 231, 63, 29);
- createAccountPanel.add(btnBack);
- JButton btnLogin = new JButton("Login");
- btnLogin.addActionListener(new ActionListener() {
- // call the query to check if user exists
- // insertIntoDB code(getFirstNameField());
- // if yes
- public void actionPerformed(ActionEvent e) {
- // check if user exists
- if(FunctionDB.isUserRegistered(loginField.getText()) ){
- if(FunctionDB.checkPassword(loginField.getText(),passwordField.getText())){
- loginPanel.setVisible(false);
- homePanel.setVisible(true);
- }
- }
- }
- });
- btnLogin.setBounds(225, 172, 117, 29);
- loginPanel.add(btnLogin);
- JButton btnCreateAccount = new JButton("Create New Account");
- btnCreateAccount.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- // set current panel to not be visible
- loginPanel.setVisible(false);
- createAccountPanel.setVisible(true);
- }
- });
- btnCreateAccount.setFont(new Font("Lucida Grande", Font.PLAIN, 8));
- btnCreateAccount.setBounds(50, 219, 117, 29);
- loginPanel.add(btnCreateAccount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement