Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. package CardGame;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import java.awt.CardLayout;
  7. import javax.swing.JPanel;
  8. import java.awt.Color;
  9. import javax.swing.JTextField;
  10. import javax.swing.JPasswordField;
  11. import javax.swing.JLabel;
  12. import javax.swing.JButton;
  13. import java.awt.Font;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.ActionEvent;
  16.  
  17. /**
  18. * This class contains the GUI for the blackjack game for first prototype
  19. * future iterations will be split up into classes and functions as discussed.
  20. *
  21. * @Author Lois Holman and Alex Davenport
  22. *
  23. * @version 2017-03-06
  24. *
  25. */
  26.  
  27.  
  28.  
  29. public class GameGUI {
  30.  
  31. private JFrame frame;
  32. private JTextField loginField;
  33. private JPasswordField passwordField;
  34. private JTextField firstnameField;
  35. private JTextField lastnameField;
  36. private JTextField usernameField;
  37. private JTextField emailField;
  38. private JPasswordField createpasswordField;
  39. private JPasswordField conpasswordField;
  40.  
  41. /**
  42. * Launch the application.
  43. */
  44. public static void main(String[] args) {
  45. EventQueue.invokeLater(new Runnable() {
  46. public void run() {
  47. try {
  48. GameGUI window = new GameGUI();
  49. window.frame.setVisible(true);
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. });
  55. }
  56.  
  57. /**
  58. * Create the application.
  59. */
  60. public GameGUI() {
  61. initialize();
  62. }
  63.  
  64. /**
  65. * Initialize the contents of the frame.
  66. */
  67. private void initialize() {
  68. frame = new JFrame();
  69. frame.setBounds(100, 100, 450, 300);
  70. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  71. frame.getContentPane().setLayout(new CardLayout(0, 0));
  72.  
  73. final JPanel loginPanel = new JPanel();
  74. loginPanel.setBackground(new Color(0, 100, 0));
  75. frame.getContentPane().add(loginPanel, "name_260916078888005");
  76. loginPanel.setLayout(null);
  77.  
  78. final JPanel createAccountPanel = new JPanel();
  79. createAccountPanel.setForeground(new Color(255, 255, 255));
  80. createAccountPanel.setBackground(new Color(0, 100, 0));
  81. frame.getContentPane().add(createAccountPanel, "name_260954822097931");
  82. createAccountPanel.setLayout(null);
  83.  
  84.  
  85. loginField = new JTextField();
  86. loginField.setBounds(217, 79, 130, 26);
  87. loginPanel.add(loginField);
  88. loginField.setColumns(10);
  89.  
  90. passwordField = new JPasswordField();
  91. passwordField.setBounds(217, 134, 130, 26);
  92. loginPanel.add(passwordField);
  93.  
  94. JLabel lblLogin = new JLabel("Login");
  95. lblLogin.setForeground(new Color(255, 255, 255));
  96. lblLogin.setBounds(50, 79, 61, 16);
  97. loginPanel.add(lblLogin);
  98.  
  99. JLabel lblPassword = new JLabel("Password");
  100. lblPassword.setForeground(new Color(255, 255, 255));
  101. lblPassword.setBounds(50, 139, 61, 16);
  102. loginPanel.add(lblPassword);
  103.  
  104. JLabel lblWhereDreamsAre = new JLabel("Where dreams are made <3.... </3");
  105. lblWhereDreamsAre.setForeground(new Color(255, 255, 255));
  106. lblWhereDreamsAre.setBounds(25, 6, 232, 16);
  107. loginPanel.add(lblWhereDreamsAre);
  108.  
  109.  
  110. firstnameField = new JTextField();
  111. firstnameField.setBounds(225, 34, 130, 26);
  112. createAccountPanel.add(firstnameField);
  113. firstnameField.setColumns(10);
  114.  
  115. JLabel lblCreateAccount = new JLabel("Create Account");
  116. lblCreateAccount.setForeground(new Color(255, 255, 255));
  117. lblCreateAccount.setBounds(133, 6, 130, 16);
  118. createAccountPanel.add(lblCreateAccount);
  119.  
  120. JLabel lblFirstName = new JLabel("First Name");
  121. lblFirstName.setForeground(new Color(255, 255, 255));
  122. lblFirstName.setBounds(45, 39, 112, 16);
  123. createAccountPanel.add(lblFirstName);
  124.  
  125. JLabel lblLastName = new JLabel("Last Name\n");
  126. lblLastName.setForeground(new Color(255, 255, 255));
  127. lblLastName.setBounds(45, 82, 112, 16);
  128. createAccountPanel.add(lblLastName);
  129.  
  130. JLabel lblUsername = new JLabel("Username (must be unique)\n");
  131. lblUsername.setForeground(new Color(255, 255, 255));
  132. lblUsername.setBounds(45, 110, 185, 16);
  133. createAccountPanel.add(lblUsername);
  134.  
  135. JLabel lblEmailAddress = new JLabel("Email Address\n");
  136. lblEmailAddress.setForeground(new Color(255, 255, 255));
  137. lblEmailAddress.setBounds(45, 143, 112, 16);
  138. createAccountPanel.add(lblEmailAddress);
  139.  
  140. JLabel lblPassword_1 = new JLabel("Password\n");
  141. lblPassword_1.setForeground(new Color(255, 255, 255));
  142. lblPassword_1.setBounds(45, 171, 112, 16);
  143. createAccountPanel.add(lblPassword_1);
  144.  
  145. lastnameField = new JTextField();
  146. lastnameField.setBounds(225, 77, 130, 26);
  147. createAccountPanel.add(lastnameField);
  148. lastnameField.setColumns(10);
  149.  
  150. usernameField = new JTextField();
  151. usernameField.setBounds(225, 105, 130, 26);
  152. createAccountPanel.add(usernameField);
  153. usernameField.setColumns(10);
  154.  
  155. emailField = new JTextField();
  156. emailField.setBounds(225, 138, 130, 26);
  157. createAccountPanel.add(emailField);
  158. emailField.setColumns(10);
  159.  
  160. JLabel lblConfirmPassword = new JLabel("Confirm Password\n");
  161. lblConfirmPassword.setForeground(new Color(255, 255, 255));
  162. lblConfirmPassword.setBounds(45, 199, 138, 16);
  163. createAccountPanel.add(lblConfirmPassword);
  164.  
  165. createpasswordField = new JPasswordField();
  166. createpasswordField.setBounds(225, 166, 130, 26);
  167. createAccountPanel.add(createpasswordField);
  168.  
  169. conpasswordField = new JPasswordField();
  170. conpasswordField.setBounds(225, 194, 130, 26);
  171. createAccountPanel.add(conpasswordField);
  172.  
  173. final JPanel homePanel = new JPanel();
  174. homePanel.setBackground(new Color(0, 100, 0));
  175. frame.getContentPane().add(homePanel, "name_260958193000997");
  176. homePanel.setLayout(null);
  177.  
  178. JLabel lblHomepageWelcome = new JLabel("Homepage Welcome!");
  179. lblHomepageWelcome.setForeground(new Color(255, 255, 255));
  180. lblHomepageWelcome.setBounds(23, 6, 188, 16);
  181. homePanel.add(lblHomepageWelcome);
  182.  
  183.  
  184. JButton btnLogout = new JButton("Logout");
  185. btnLogout.addActionListener(new ActionListener() {
  186. public void actionPerformed(ActionEvent e) {
  187. homePanel.setVisible(false);
  188. loginPanel.setVisible(true);
  189.  
  190. }
  191. });
  192. btnLogout.setBounds(291, 221, 117, 29);
  193. homePanel.add(btnLogout);
  194.  
  195.  
  196. JButton btnCreateNewUser = new JButton("Create new user");
  197. btnCreateNewUser.addActionListener(new ActionListener() {
  198.  
  199. //check for email match as well
  200. // googlr this
  201. @SuppressWarnings("deprecation")
  202. public void actionPerformed(ActionEvent e) {
  203. if (!functionDB.isUserRegistered(usernameField.getText())){
  204. if(conpasswordField.getText() == createpasswordField.getText()){
  205. functionDB.insertUserIntoDatabase(new User(usernameField.getText(),createpasswordField.getText(),firstnameField.getText(),lastnameField.getText(), emailField.getText())); //add email
  206. createAccountPanel.setVisible(false);
  207. homePanel.setVisible(true);
  208. }
  209. }
  210. // query for username and email unique then allow it and save to DB etc
  211.  
  212. }
  213. });
  214. btnCreateNewUser.setBounds(133, 231, 175, 29);
  215. createAccountPanel.add(btnCreateNewUser);
  216.  
  217.  
  218. JButton btnBack = new JButton("Back");
  219. btnBack.addActionListener(new ActionListener() {
  220. public void actionPerformed(ActionEvent e) {
  221. createAccountPanel.setVisible(false);
  222. loginPanel.setVisible(true);
  223. }
  224. });
  225.  
  226. btnBack.setBounds(6, 231, 63, 29);
  227. createAccountPanel.add(btnBack);
  228.  
  229.  
  230.  
  231. JButton btnLogin = new JButton("Login");
  232. btnLogin.addActionListener(new ActionListener() {
  233.  
  234. // call the query to check if user exists
  235. // insertIntoDB code(getFirstNameField());
  236. // if yes
  237.  
  238. public void actionPerformed(ActionEvent e) {
  239. // check if user exists
  240. if(FunctionDB.isUserRegistered(loginField.getText()) ){
  241. if(FunctionDB.checkPassword(loginField.getText(),passwordField.getText())){
  242. loginPanel.setVisible(false);
  243. homePanel.setVisible(true);
  244. }
  245. }
  246.  
  247.  
  248. }
  249.  
  250.  
  251.  
  252. });
  253. btnLogin.setBounds(225, 172, 117, 29);
  254. loginPanel.add(btnLogin);
  255.  
  256.  
  257. JButton btnCreateAccount = new JButton("Create New Account");
  258. btnCreateAccount.addActionListener(new ActionListener() {
  259.  
  260. public void actionPerformed(ActionEvent e) {
  261.  
  262. // set current panel to not be visible
  263. loginPanel.setVisible(false);
  264. createAccountPanel.setVisible(true);
  265.  
  266. }
  267. });
  268. btnCreateAccount.setFont(new Font("Lucida Grande", Font.PLAIN, 8));
  269. btnCreateAccount.setBounds(50, 219, 117, 29);
  270. loginPanel.add(btnCreateAccount);
  271.  
  272. }
  273.  
  274.  
  275.  
  276.  
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement