Advertisement
Guest User

Untitled

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