Advertisement
Guest User

Untitled

a guest
May 30th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. package finalproject;
  2.  
  3. import java.awt.*;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import java.awt.Toolkit;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.util.ArrayList;
  13.  
  14. @SuppressWarnings("serial")
  15. public class CfwPrimary extends JFrame {
  16.  
  17. private JPanel mainPanel;
  18. private LoginPanel loginPanel = new LoginPanel();
  19. private UserPanel userPanel = new UserPanel();
  20. private RegisterPanel registerPanel = new RegisterPanel();
  21.  
  22. private CardLayout cardMain = new CardLayout(0, 0);
  23. private static ArrayList<Account> accounts = new ArrayList<>();
  24.  
  25. public static void main(String[] args) {
  26.  
  27. // Account Constructor (String name, char[] pass, double balance, int type, String email, long creditCard)
  28. accounts.add(new Account("BasicUser", "basicuser", 20000, 0, "isuck@life.com", 321));
  29. accounts.add(new Account("Investor", "investor", 100000, 1, "ieat@arbys.com", 123456));
  30. accounts.add(new Account("Administrator", "administrator", 250000, 2, "elitedarklord666@aol.com", 13371337));
  31.  
  32. EventQueue.invokeLater(new Runnable() {
  33. public void run() {
  34. try {
  35. CfwPrimary frame = new CfwPrimary();
  36. frame.setVisible(true);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
  41. });
  42. }
  43.  
  44. /**
  45. * Create the frame.
  46. */
  47. public CfwPrimary() {
  48. setResizable(false);
  49. setIconImage(Toolkit.getDefaultToolkit().getImage(CfwPrimary.class.getResource("/finalproject/cfwdicon.png")));
  50. setTitle("cFwd");
  51. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52. setSize(660, 430);
  53. this.setLocationRelativeTo(null);
  54.  
  55. this.mainPanel = new JPanel();
  56. this.mainPanel.setLayout(this.cardMain);
  57.  
  58. this.mainPanel.add(this.loginPanel, "login");
  59. this.mainPanel.add(this.userPanel, "user");
  60. this.mainPanel.add(this.registerPanel, "register");
  61.  
  62. showCardPanel("login");
  63.  
  64. getContentPane().add(this.mainPanel);
  65.  
  66. this.loginPanel.AddLoginListener(new ActionListener() {
  67.  
  68. @Override
  69. public void actionPerformed(ActionEvent e) {
  70. //JOptionPane.showMessageDialog(null, "Welcome!");
  71. userPanel.setPermission(loginPanel.getPermission());
  72. Transaction.setBalance(loginPanel.getBalance());
  73. UserPanel.setBalanceField(Transaction.getBalance());
  74. CfwPrimary.this.showCardPanel("user");
  75. }
  76. });
  77.  
  78. this.loginPanel.AddRegisterListener(new ActionListener() {
  79.  
  80. @Override
  81. public void actionPerformed(ActionEvent e) {
  82. CfwPrimary.this.showCardPanel("register");
  83. }
  84. });
  85.  
  86. this.userPanel.AddLogoutListener(new ActionListener() {
  87.  
  88. @Override
  89. public void actionPerformed(ActionEvent e) {
  90. CfwPrimary.this.showCardPanel("login");
  91. JOptionPane.showMessageDialog(null, "Logged out successfully.");
  92. }
  93. });
  94.  
  95. this.registerPanel.AddCancelListener(new ActionListener() {
  96.  
  97. @Override
  98. public void actionPerformed(ActionEvent e) {
  99. CfwPrimary.this.showCardPanel("login");
  100. }
  101. });
  102.  
  103. }
  104.  
  105.  
  106. private void showCardPanel(String name){
  107. this.cardMain.show(mainPanel, name);
  108. }
  109.  
  110. public static ArrayList<Account> getAccounts(){
  111. return accounts;
  112. }
  113.  
  114. public static void addAccount(Account newAccount){
  115. accounts.add(newAccount);
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement