Advertisement
Guest User

MyWinBuild.java

a guest
Jan 31st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JPanel;
  3. import javax.swing.border.EmptyBorder;
  4. import javax.swing.JTextField;
  5. import javax.swing.JButton;
  6. import javax.swing.JLabel;
  7.  
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ActionEvent;
  10. import javax.swing.JPasswordField;
  11.  
  12. public class MyWinBuild extends JFrame {
  13.  
  14. private JPanel contentPane;
  15. private JTextField firstName;
  16. private JLabel firstNameLabel;
  17. private JTextField lastName;
  18. private JLabel lastNameLabel;
  19. private JTextField userName;
  20. private JPasswordField passwordField;
  21. public static MyWinBuild createAccountFrame = new MyWinBuild();
  22.  
  23.  
  24. public static void main(String[] args)
  25. {
  26. createAccountFrame.setVisible(true);
  27.  
  28. }
  29. //Create the frame.
  30. public MyWinBuild() {
  31.  
  32. setType(Type.UTILITY);
  33. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34. setBounds(100, 100, 450, 300);
  35. contentPane = new JPanel();
  36. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  37. setContentPane(contentPane);
  38. contentPane.setLayout(null);
  39.  
  40.  
  41. //This is the info label.
  42. JLabel InforLabel = new JLabel("Fill in the information below");
  43. InforLabel.setBounds(130, 13, 169, 16);
  44. contentPane.add(InforLabel);
  45.  
  46. /*
  47. * FirstName
  48. */
  49. //First Name label
  50. firstNameLabel = new JLabel("First Name");
  51. firstNameLabel.setBounds(85, 57, 68, 16);
  52. contentPane.add(firstNameLabel);
  53.  
  54. //First Name input
  55. firstName = new JTextField();
  56. firstName.setBounds(61, 86, 116, 22);
  57. contentPane.add(firstName);
  58. firstName.setColumns(10);
  59.  
  60. /*
  61. * LastName
  62. */
  63. //Last Name label
  64. lastNameLabel = new JLabel("Last Name");
  65. lastNameLabel.setBounds(266, 57, 68, 16);
  66. contentPane.add(lastNameLabel);
  67.  
  68. //Last Name Input
  69. lastName = new JTextField();
  70. lastName.setBounds(233, 86, 133, 22);
  71. contentPane.add(lastName);
  72. lastName.setColumns(10);
  73.  
  74. /*
  75. * UserName
  76. */
  77. //User Name label
  78. JLabel userNameLabel = new JLabel("User Name");
  79. userNameLabel.setBounds(85, 120, 68, 16);
  80. contentPane.add(userNameLabel);
  81.  
  82. //User Name input
  83. userName = new JTextField();
  84. userName.setBounds(61, 149, 116, 22);
  85. contentPane.add(userName);
  86. userName.setColumns(10);
  87.  
  88. /*
  89. * Password
  90. */
  91. //Password label
  92. JLabel passwordLabel = new JLabel("Password");
  93. passwordLabel.setBounds(266, 121, 68, 16);
  94. contentPane.add(passwordLabel);
  95.  
  96. //Password input
  97. passwordField = new JPasswordField();
  98. passwordField.setBounds(233, 149, 133, 22);
  99. contentPane.add(passwordField);
  100.  
  101. /*
  102. * Button
  103. */
  104. JButton applyBtn = new JButton("Apply");
  105. applyBtn.addActionListener(new ActionListener() {
  106. public void actionPerformed(ActionEvent e)
  107. {
  108. String fn = firstName.getText(); //Set a new variable "fn" to the textinput.
  109. String ln = lastName.getText(); //Set a new variable "ln" to the textinput.
  110. String username = userName.getText(); //Set a new variable "username" to the textinput.
  111. char[] password = passwordField.getPassword(); //Creates a list "password[]" to store the Password.
  112.  
  113. //Creates a new Database.
  114. DataBase db = new DataBase();
  115.  
  116. //Set the name in the DataBase class.
  117. db.setFirstname(fn);
  118. db.setLastname(ln);
  119. db.setUsername(username);
  120. db.setPassword(password);
  121. db.save();
  122. System.out.println(db.getFirstname()); //For Testing.
  123. System.out.println(db.getLastname());
  124. System.out.println(db.getUsername());
  125. System.out.println(db.getPassword());
  126.  
  127. //Create a new WinBuild for the LoginScreen.
  128. LoginMyWinBuild newWindow = new LoginMyWinBuild();
  129.  
  130. //Set the current window to visibility to false.
  131. createAccountFrame.setVisible(false);
  132.  
  133. //And then set the New login Window to visibility true.
  134. newWindow.setVisible(true);
  135.  
  136. }
  137. });
  138. applyBtn.setBounds(323, 215, 97, 25);
  139. contentPane.add(applyBtn);
  140.  
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement