Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. // Joshua Godfrey
  2.  
  3. //import statements
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7. import javax.swing.UIManager.*;
  8. import java.awt.event.AdjustmentListener;
  9. import java.awt.event.ActionEvent;
  10.  
  11.  
  12. public class ATMGUI extends JFrame implements ActionListener
  13.  
  14. {
  15.  
  16. JTextArea screen;
  17. JPanel textPanel;
  18. JPanel inputPanel;
  19. JPanel sidePanel;
  20. JButton [] numButtons;
  21. JTextField [] slips;
  22. int state = 1;
  23.  
  24. //Example of Adapter Class
  25.  
  26. private class Terminator extends WindowAdapter {
  27. public void windowClosing(WindowEvent e)
  28. {
  29.  
  30. System.out.println("Window closing selected: terminating program");
  31. System.exit(0);
  32.  
  33. }
  34.  
  35. }
  36.  
  37. public ATMGUI()
  38. {
  39. try
  40. {
  41. for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
  42. System.out.println(info.getClassName());
  43. if ("Nimbus".equals(info.getName())) {
  44. UIManager.setLookAndFeel(info.getClassName());
  45. break;
  46.  
  47. }
  48.  
  49. }
  50.  
  51. } catch (UnsupportedLookAndFeelException e) { // handle exception
  52. } catch (ClassNotFoundException e) { // handle exception
  53. } catch (InstantiationException e) { // handle exception
  54. } catch (IllegalAccessException e) { // handle exception}
  55.  
  56. }
  57.  
  58. setTitle("ATM Machine by Godfrey");
  59. setSize(450, 350);
  60. Container content = getContentPane();
  61. content.setLayout ( new FlowLayout() );
  62.  
  63. numButtons = new JButton[11];
  64. slips = new JTextField[2];
  65. screen = new JTextArea(6,35);
  66. for ( int i = 0; i <9 ; i++ )
  67. {
  68.  
  69. numButtons[i] = new JButton ( Integer.toString ( i+1 ) );
  70.  
  71. }
  72.  
  73. numButtons[9] = new JButton ( "0" );
  74. numButtons[10] = new JButton ( "Enter" );
  75.  
  76. slips[0] = new JTextField ("Take cash here");
  77. slips[1] = new JTextField ("Insert deposit slip here");
  78.  
  79.  
  80. textPanel = new JPanel();
  81. textPanel.setSize(200, 300);
  82. textPanel.setLayout ( new GridLayout(1,1) );
  83. textPanel.setBorder ( BorderFactory.createLineBorder ( Color.LIGHT_GRAY, 2 ) );
  84. textPanel.add( screen );
  85. content.add(textPanel);
  86.  
  87. inputPanel = new JPanel();
  88. inputPanel.setSize(200, 300);
  89. inputPanel.setLayout ( new GridLayout(4,3) );
  90. inputPanel.setBorder ( BorderFactory.createLineBorder ( Color.LIGHT_GRAY, 2 ) );
  91. for ( int i = 0; i <numButtons.length ; i++ )
  92. {
  93.  
  94. numButtons[i].addActionListener ( this );
  95. inputPanel.add ( numButtons[i] );
  96.  
  97. }
  98. inputPanel.add ( slips[0] );
  99. inputPanel.add ( slips[1] );
  100. content.add(inputPanel);
  101.  
  102. sidePanel = new JPanel();
  103. sidePanel.setSize(200, 200);
  104. sidePanel.setLayout ( new GridLayout(4,1) );
  105. sidePanel.setBorder ( BorderFactory.createLineBorder ( Color.LIGHT_GRAY, 2 ) );
  106. sidePanel.add ( slips[0] );
  107. sidePanel.add ( slips[1] );
  108. content.add(sidePanel);
  109.  
  110. setVisible(true);
  111. addWindowListener(new Terminator());
  112. screen.append("Welcome\n\nEnter your account number: ");
  113.  
  114. }
  115.  
  116. public void getState1()
  117. {
  118. screen.setText("");
  119. screen.append("Welcome\n\nEnter your account number: ");
  120. }
  121.  
  122. public void getState2()
  123. {
  124. screen.append("\n\nEnter your PIN: ");
  125. }
  126.  
  127. public void getState3()
  128. {
  129. screen.setText("");
  130. screen.append("1: View Balance\n2: Withdraw funds\n3: Add funds\n4: Terminate transaction");
  131. }
  132.  
  133.  
  134. public void actionPerformed(ActionEvent evt)
  135. {
  136.  
  137. Object source = evt.getSource();
  138.  
  139. if(source==numButtons[0])
  140. {
  141. screen.append("1");
  142. }
  143. if(source==numButtons[1])
  144. {
  145. screen.append("2");
  146. }
  147. if(source==numButtons[2])
  148. {
  149. screen.append("3");
  150. }
  151. if(source==numButtons[3])
  152. {
  153. if(state ==1 )
  154. screen.append("4");
  155. else if(state == 3)
  156. {
  157. getState1();
  158.  
  159. }
  160. else
  161. screen.append("4");
  162. }
  163. if(source==numButtons[4])
  164. {
  165. screen.append("5");
  166. }
  167. if(source==numButtons[5])
  168. {
  169. screen.append("6");
  170. }
  171. if(source==numButtons[6])
  172. {
  173. screen.append("7");
  174. }
  175. if(source==numButtons[7])
  176. {
  177. screen.append("8");
  178. }
  179. if(source==numButtons[8])
  180. {
  181. screen.append("9");
  182. }
  183. if(source==numButtons[9])
  184. {
  185. screen.append("0");
  186. }
  187. if(source==numButtons[10])
  188. {
  189. state = 1;
  190. if (state == 1)
  191. {
  192. getState2();
  193. state = 2;
  194.  
  195. }
  196. else if (state == 2)
  197. {
  198. getState3();
  199. state = 3;
  200. }
  201. else
  202. getState1();
  203. }
  204.  
  205. }
  206.  
  207. public static void main(String args[])
  208. {
  209. ATMGUI test = new ATMGUI();
  210.  
  211. }
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement