Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. import javax.swing.*;
  4.  
  5. import java.awt.event.*;
  6. import java.io.PrintWriter;
  7. import java.io.File;
  8.  
  9.  
  10. public class BankSimulator extends JFrame implements ActionListener
  11.  
  12.  
  13. {
  14.  
  15.  
  16. JTextField username = new JTextField(10);
  17. JTextField password = new JTextField(10);
  18. JTextField name = new JTextField(10);
  19. JTextField setPassword = new JTextField(5);
  20. JLabel userlbl = new JLabel("Username");
  21. JLabel passlbl = new JLabel("Password");
  22. JRadioButton option1 = new JRadioButton("Basic Account");
  23. JRadioButton option2 = new JRadioButton("Saver Account");
  24. JRadioButton option3 = new JRadioButton("Super Account");
  25. JButton logbtn = new JButton("Log In");
  26. JButton regbtn = new JButton("Register");
  27. JButton showkeyboard = new JButton("showkeyboard");
  28. JButton createbtn = new JButton("Create Account");
  29. JButton[] btn1 = new JButton[10];
  30. JButton[] btn2 = new JButton[10];
  31. JButton[] btn3 = new JButton[9];
  32. JButton[] btn4 = new JButton[7];
  33.  
  34.  
  35.  
  36.  
  37. public static void main(String[] args)
  38. {
  39. BankSimulator bm = new BankSimulator();
  40.  
  41. }
  42.  
  43. public BankSimulator()
  44.  
  45. {
  46. setLayout(null);
  47. setSize(850,700);
  48. setTitle("Bank Simulator");
  49. username.setBounds(350, 150, 130, 20);
  50. add(username);
  51. password.setBounds(350,180,130,20);
  52. add(password);
  53. option1.setBounds(440,180, 130,20);
  54. option2.setBounds(440,210, 130,20);
  55. option3.setBounds(440,240, 130, 20);
  56. add(option1);
  57. add(option2);
  58. add(option3);
  59. option1.setVisible(false);
  60. option2.setVisible(false);
  61. option3.setVisible(false);
  62. name.setBounds(440,150,130,20);
  63. add(name);
  64. name.setVisible(false);
  65. setPassword.setBounds(440,123,130,20);
  66. add(setPassword);
  67. setPassword.setVisible(false);
  68. userlbl.setBounds(288,150,130,20);
  69. add(userlbl);
  70. passlbl.setBounds(288,180, 130,20);
  71. add(passlbl);
  72. logbtn.setBounds(341,220,150,30);
  73. add(logbtn);
  74. createbtn.setBounds(435,270,150,30);
  75. add(createbtn);
  76. createbtn.setVisible(false);
  77. logbtn.addActionListener(this);
  78. regbtn.setBounds(341,260,150,30);
  79. add(regbtn);
  80. regbtn.addActionListener(this);
  81.  
  82.  
  83.  
  84. showkeyboard.setBounds(341, 270, 150,30);
  85. add(showkeyboard);
  86. showkeyboard.addActionListener(new ActionListener()
  87. {
  88. @Override
  89. public void actionPerformed(ActionEvent e) {
  90. showkeyboard();
  91. }
  92.  
  93. });
  94. setVisible(true);
  95.  
  96. }
  97.  
  98. public void showkeyboard()
  99. {
  100.  
  101. String nos = "1234567890";
  102. String alphabet = "abcdefghij";
  103. String alphabet1 = "klmnopqrs";
  104. String alphabet2 = "tuvwxyz";
  105.  
  106. JFrame myFrame = new JFrame();
  107. myFrame.setSize(586, 205);
  108. JPanel myPanel = new JPanel();
  109. JPanel myPanel1 = new JPanel();
  110. JPanel myPanel2 = new JPanel();
  111. JPanel myPanel3 = new JPanel();
  112.  
  113.  
  114. for (int i =0; i< nos.length(); i++)
  115. {
  116. btn1[i] = new JButton(nos.substring(i, i + 1));
  117. myPanel.add(btn1[i]);
  118. btn1[i].addActionListener(new ActionListener(){
  119. public void actionPerformed(ActionEvent e)
  120. {
  121. keyboardButtonPressed();
  122.  
  123. }});
  124.  
  125.  
  126. for (int i = 0; i < alphabet.length(); i++) {
  127.  
  128. btn2[i] = new JButton(alphabet.substring(i, i + 1));
  129. myPanel1.add(btn2[i]);
  130.  
  131. }
  132. for(int i = 0; i < alphabet1.length();i++){
  133. btn3[i] = new JButton(alphabet1.substring(i, i + 1));
  134. myPanel2.add(btn3[i]);
  135. }
  136.  
  137. for (int i = 0; i < alphabet2.length(); i++){
  138.  
  139. btn4[i] = new JButton(alphabet2.substring(i, i + 1));
  140. myPanel3.add(btn4[i]);
  141. }
  142.  
  143. JPanel outer = new JPanel();
  144. outer.add(myPanel);
  145. outer.add(myPanel1);
  146. outer.add(myPanel2);
  147. outer.add(myPanel3);
  148. myFrame.add(outer);
  149. myFrame.setVisible(true);
  150.  
  151.  
  152.  
  153. }
  154.  
  155.  
  156. }
  157.  
  158. public String keyboardButtonPressed(char a)
  159. {
  160.  
  161. String alreadyDisplayed = username.getText();
  162. String toDisplay = alreadyDisplayed + btn1[i].getText();
  163.  
  164. }
  165.  
  166. public void actionPerformed(ActionEvent e)
  167. {
  168.  
  169. if (e.getSource()== regbtn)
  170. {
  171. username.setVisible(false);
  172. password.setVisible(false);
  173. logbtn.setVisible(false);
  174. userlbl.setVisible(false);
  175. passlbl.setVisible(false);
  176. option1.setVisible(true);
  177. option2.setVisible(true);
  178. option3.setVisible(true);
  179. name.setVisible(true);
  180. setPassword.setVisible(true);
  181. regbtn.setVisible(false);
  182. createbtn.setVisible(true);
  183.  
  184. }
  185.  
  186.  
  187. }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement