Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6.  
  7. class GUIBank extends JFrame{
  8.  
  9. private JFrame LoginCard, LoginAdmin, LoginUser, CreateAccount,BankTransaction;
  10. private JPanel WelcomePage, WelcomeAdmin, WelcomeUser, CreateAccountP, Transaction;
  11. private JButton admin, user, admin_login, user_login, withdraw, deposit, transfer, create ;
  12. private JTextField AccessName, AccessPassword, AdminName, AdminPassword, UserID, UserPassword,
  13. WithdrawAmount, DepositAmount, TransferAmountfrom, TransferAmountto,AccNo, NewUserName, NewUserID, NewUserType;
  14. private JLabel enterAccessName,enterAccessPassword,enterAdminName,enterAdminPassword,enterUserName,
  15. enterUserPassword,enterNewUserID, enterNewUserType, enterNewUserName,enterUserID, enterWithdraw, enterDeposit, entersource,
  16. enterdestination;
  17. /*private JLabel lab;*/
  18.  
  19. public GUIBank()
  20. {
  21. Bank_Welcome_Page();
  22. //Admin_Welcome_Page();
  23. //User_Welcome_Page();
  24. //Create_Account();
  25. //Bank_Transaction();
  26.  
  27. }
  28.  
  29. public void Bank_Welcome_Page()
  30. {
  31. LoginCard= new JFrame(" Welcome to the Bank!");
  32. LoginCard.setSize(500,500);
  33. LoginCard.setLayout(new GridLayout(6, 6));
  34. LoginCard.setVisible(true);
  35. LoginCard.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36. LoginCard.addWindowListener(new WindowAdapter() {
  37.  
  38. public void windowClosing(WindowEvent windowEvent){
  39. //System.exit(0);
  40. //swingControlDemo.prepareGUI();
  41.  
  42.  
  43. }
  44. });
  45.  
  46. final Map<String, String> unamepass;
  47. unamepass = new HashMap<String, String>();
  48. /*
  49. * Only two user exists ,
  50. */
  51. unamepass.put("ritu", "abc");
  52. unamepass.put("kitu", "xyz");
  53.  
  54.  
  55. WelcomePage = new JPanel();
  56. WelcomePage.setLayout(new FlowLayout());
  57. LoginCard.setBackground(Color.RED);
  58.  
  59.  
  60. admin = new JButton("Admin");
  61. admin.setSize(10, 10);
  62.  
  63.  
  64. user = new JButton("User");
  65. user.setSize(10,10);
  66.  
  67.  
  68.  
  69. enterAccessName= new JLabel("Enter Access Name",JLabel.RIGHT);
  70. enterAccessName.setSize(300,200);
  71. AccessName = new JTextField(10);
  72. AccessName.setSize(10,50);
  73. //AccessName.setAlignmentY(0);
  74.  
  75. enterAccessPassword = new JLabel("Enter Password",JLabel.RIGHT);
  76. AccessPassword = new JTextField(10);
  77.  
  78. /*lab = new JLabel("This is test Label");*/
  79. LoginCard.add(WelcomePage);
  80.  
  81. WelcomePage.add(enterAccessName);
  82. WelcomePage.add(AccessName);
  83. WelcomePage.add(enterAccessPassword);
  84. WelcomePage.add(AccessPassword);
  85. WelcomePage.add(admin);
  86. WelcomePage.add(user);
  87.  
  88. admin.addActionListener(new ActionListener() {
  89. public void actionPerformed(ActionEvent e) {
  90. String uname = adduname.getText();
  91. String pass = addpass.getText();
  92. String mychoice = choice.getText();
  93. String data = "";
  94.  
  95. if ( unamepass.containsKey(uname)) {
  96. //System.out.println(uname+pass);
  97. String val = unamepass.get(uname);
  98. if (val.equals(pass)) {
  99. flag = 1;
  100. } else {
  101. System.out.println("username password does not match, close window");
  102. flag = 0;
  103. }
  104. }
  105. if ( flag == 1) {
  106. System.out.println("username password matches, close window");
  107. if (mychoice.equals("R"))
  108. flag = 2;
  109. if (mychoice.equals("A"))
  110. flag = 3;
  111. }
  112.  
  113. }
  114. });
  115.  
  116. user.addActionListener(new ActionListener() {
  117. public void actionPerformed(ActionEvent e) {
  118. String uname = adduname.getText();
  119. String pass = addpass.getText();
  120. String mychoice = choice.getText();
  121. String data = "";
  122.  
  123. if ( unamepass.containsKey(uname)) {
  124. //System.out.println(uname+pass);
  125. String val = unamepass.get(uname);
  126. if (val.equals(pass)) {
  127. flag = 1;
  128. } else {
  129. System.out.println("username password does not match, close window");
  130. flag = 0;
  131. }
  132. }
  133. if ( flag == 1) {
  134. System.out.println("username password matches, close window");
  135. if (mychoice.equals("R"))
  136. flag = 2;
  137. if (mychoice.equals("A"))
  138. flag = 3;
  139. }
  140.  
  141. }
  142. });
  143.  
  144. //LoginCard.add(WelcomePage);
  145. LoginCard.setVisible(true);
  146.  
  147.  
  148. }
  149.  
  150. public void Admin_Welcome_Page()
  151. {
  152. LoginAdmin= new JFrame(" Welcome Admin!");
  153. LoginAdmin.setSize(500,500);
  154. LoginAdmin.setLayout(new GridLayout(6, 6));
  155. LoginAdmin.setVisible(true);
  156. LoginAdmin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  157.  
  158. WelcomeAdmin = new JPanel();
  159. WelcomeAdmin.setLayout(new FlowLayout());
  160. LoginAdmin.setBackground(Color.RED);
  161.  
  162.  
  163. admin_login = new JButton("Login");
  164. admin_login.setSize(10, 10);
  165.  
  166. enterAdminName= new JLabel("Enter Admin Name",JLabel.RIGHT);
  167. enterAdminName.setSize(300,200);
  168. AdminName = new JTextField(10);
  169. AdminName.setSize(10,50);
  170. //AccessName.setAlignmentY(0);
  171.  
  172. enterAdminPassword= new JLabel("Enter Password",JLabel.RIGHT);
  173. enterAdminPassword.setSize(300,200);
  174. AdminPassword = new JTextField(10);
  175. AdminPassword.setSize(10,50);
  176.  
  177.  
  178.  
  179. /*admin.addActionListener(new ActionListener() {
  180.  
  181. public void actionPerformed(ActionEvent e){
  182.  
  183. }
  184.  
  185. });
  186.  
  187. /*lab = new JLabel("This is test Label");*/
  188. LoginAdmin.add(WelcomeAdmin);
  189.  
  190. WelcomeAdmin.add(enterAdminName);
  191. WelcomeAdmin.add(AdminName);
  192. WelcomeAdmin.add(enterAdminPassword);
  193. WelcomeAdmin.add(AdminPassword);
  194. WelcomeAdmin.add(admin_login);
  195.  
  196.  
  197. //LoginCard.add(WelcomePage);
  198. LoginAdmin.setVisible(true);
  199. }
  200.  
  201. public void User_Welcome_Page()
  202. {
  203. LoginUser= new JFrame(" Welcome User!");
  204. LoginUser.setSize(500,500);
  205. LoginUser.setLayout(new GridLayout(6, 6));
  206. LoginUser.setVisible(true);
  207. LoginUser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  208.  
  209. WelcomeUser = new JPanel();
  210. WelcomeUser.setLayout(new FlowLayout());
  211. LoginUser.setBackground(Color.RED);
  212.  
  213.  
  214. user_login = new JButton("Login");
  215. user_login.setSize(10, 10);
  216.  
  217. enterUserName= new JLabel("Enter User ID",JLabel.RIGHT);
  218. enterUserName.setSize(300,200);
  219. UserID = new JTextField(10);
  220. UserID.setSize(10,50);
  221. //AccessName.setAlignmentY(0);
  222.  
  223. enterUserPassword= new JLabel("Enter Password",JLabel.RIGHT);
  224. enterUserPassword.setSize(300,200);
  225. UserPassword = new JTextField(10);
  226. UserPassword.setSize(10,50);
  227.  
  228.  
  229.  
  230. /*admin.addActionListener(new ActionListener() {
  231.  
  232. public void actionPerformed(ActionEvent e){
  233.  
  234. }
  235.  
  236. });
  237.  
  238. /*lab = new JLabel("This is test Label");*/
  239. LoginUser.add(WelcomeUser);
  240.  
  241. WelcomeUser.add(enterUserName);
  242. WelcomeUser.add(UserID);
  243. WelcomeUser.add(enterUserPassword);
  244. WelcomeUser.add(UserPassword);
  245. WelcomeUser.add(user_login);
  246.  
  247.  
  248. //LoginCard.add(WelcomePage);
  249. LoginUser.setVisible(true);
  250. }
  251.  
  252. public void Create_Account()
  253. {
  254. CreateAccount= new JFrame(" Create Account Holder");
  255. CreateAccount.setSize(500,500);
  256. CreateAccount.setLayout(new GridLayout(6, 6));
  257. CreateAccount.setVisible(true);
  258. CreateAccount.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  259.  
  260. CreateAccountP = new JPanel();
  261. CreateAccountP.setLayout(new FlowLayout());
  262. CreateAccount.setBackground(Color.RED);
  263.  
  264.  
  265. create = new JButton("Create Account");
  266. create.setSize(10, 10);
  267.  
  268. enterNewUserName= new JLabel("Enter New User Name",JLabel.RIGHT);
  269. enterNewUserName.setSize(300,200);
  270. enterNewUserID= new JLabel("Enter New User ID",JLabel.RIGHT);
  271. enterNewUserID.setSize(300,200);
  272. enterNewUserType= new JLabel("Enter New User Type Checkin/Savings",JLabel.RIGHT);
  273. enterNewUserType.setSize(300,200);
  274. NewUserName = new JTextField(10);
  275. NewUserName.setSize(10,50);
  276. NewUserID = new JTextField(10);
  277. NewUserID.setSize(10,50);
  278. NewUserType = new JTextField(10);
  279. NewUserType.setSize(10,50);
  280. //AccessName.setAlignmentY(0);
  281.  
  282.  
  283.  
  284.  
  285. /*admin.addActionListener(new ActionListener() {
  286.  
  287. public void actionPerformed(ActionEvent e){
  288.  
  289. }
  290.  
  291. });
  292.  
  293. /*lab = new JLabel("This is test Label");*/
  294. CreateAccount.add(CreateAccountP);
  295.  
  296. CreateAccountP.add(enterNewUserName);
  297. CreateAccountP.add(NewUserName);
  298. CreateAccountP.add(enterNewUserID);
  299. CreateAccountP.add(NewUserID);
  300. CreateAccountP.add(enterNewUserType);
  301. CreateAccountP.add(NewUserType);
  302. CreateAccountP.add(create);
  303.  
  304.  
  305. //LoginCard.add(WelcomePage);
  306. CreateAccount.setVisible(true);
  307. }
  308.  
  309. public void Bank_Transaction()
  310. {
  311. BankTransaction= new JFrame(" Create Account Holder");
  312. BankTransaction.setSize(600,600);
  313. BankTransaction.setLayout(new GridLayout(6, 6,5,5));
  314. BankTransaction.setVisible(true);
  315. BankTransaction.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  316.  
  317.  
  318. Transaction = new JPanel();
  319. Transaction.setLayout(new FlowLayout());
  320. BankTransaction.setBackground(Color.RED);
  321.  
  322.  
  323. withdraw = new JButton("Withdraw");
  324. withdraw.setSize(10, 10);
  325. //withdraw.add(Box.createHorizontalStrut(10));
  326. deposit = new JButton("Deposit");
  327. deposit.setSize(10, 10);
  328. //deposit.add(Box.createHorizontalStrut(10));
  329. transfer = new JButton("Transfer");
  330. transfer.setSize(10, 10);
  331.  
  332. enterUserID= new JLabel("Enter User ID",JLabel.RIGHT);
  333. enterUserID.setSize(300,200);
  334. enterUserID.add(Box.createHorizontalStrut(60));
  335. enterWithdraw= new JLabel("Enter amount to be Withdrawn");
  336. enterWithdraw.setSize(300,200);
  337. enterDeposit= new JLabel("Enter amount to be deposited");
  338. enterDeposit.setSize(300,200);
  339. entersource= new JLabel("Savings/Checkin",JLabel.RIGHT);
  340. entersource.setSize(300,200);
  341. enterdestination= new JLabel("Savings/Checkin",JLabel.RIGHT);
  342. enterdestination.setSize(300,200);
  343.  
  344. AccNo = new JTextField(10);
  345. AccNo.setSize(10,50);
  346. WithdrawAmount = new JTextField(10);
  347. WithdrawAmount.setSize(10,50);
  348. DepositAmount = new JTextField(10);
  349. DepositAmount.setSize(10,50);
  350. TransferAmountfrom = new JTextField(10);
  351. TransferAmountfrom.setSize(10,50);
  352. TransferAmountto = new JTextField(10);
  353. TransferAmountto.setSize(10,50);
  354. //AccessName.setAlignmentY(0);
  355.  
  356.  
  357.  
  358.  
  359. /*admin.addActionListener(new ActionListener() {
  360.  
  361. public void actionPerformed(ActionEvent e){
  362.  
  363. }
  364.  
  365. });
  366.  
  367. /*lab = new JLabel("This is test Label");*/
  368. BankTransaction.add(Transaction);
  369.  
  370. Transaction.add(enterUserID);
  371. Transaction.add(AccNo);
  372.  
  373. Transaction.add(enterWithdraw);
  374. Transaction.add(WithdrawAmount);
  375. Transaction.add(withdraw);
  376.  
  377. Transaction.add(enterDeposit);
  378. Transaction.add(DepositAmount);
  379. Transaction.add(deposit);
  380.  
  381. Transaction.add(entersource);
  382. Transaction.add(TransferAmountfrom);
  383.  
  384.  
  385. Transaction.add(enterdestination);
  386. Transaction.add(TransferAmountto);
  387. Transaction.add(transfer);
  388.  
  389.  
  390. //LoginCard.add(WelcomePage);
  391. BankTransaction.setVisible(true);
  392. }
  393.  
  394.  
  395.  
  396. public static void main(String[] args) {
  397. // TODO Auto-generated method stub
  398.  
  399. new GUIBank();
  400.  
  401.  
  402. }
  403.  
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement