Guest User

Untitled

a guest
Jul 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. public class GUI {
  8.  
  9. private JFrame frame;
  10. private JPanel panel;
  11. private JTextField txtBegBal, txtCheAmt, txtDepAmt, txtEndBal;
  12. private JLabel begBal, cheAmt, depAmt, endBal;
  13.  
  14. public static void main(String[] args) {
  15. GUI gui1 = new GUI();
  16. gui1.CheckBookBalance();
  17. }
  18.  
  19. public void CheckBookBalance() {
  20. // Create the frame and panel //
  21.  
  22. frame = new JFrame("Checkbook Balancing Program");
  23. panel = new JPanel();
  24. //CheckingAccount check = new CheckingAccount(0,0);
  25.  
  26. // Set the background color to orange, and use a grid layout of 4 by 2 //
  27.  
  28. panel.setLayout(new GridLayout(4, 2));
  29. panel.setBackground(Color.orange);
  30.  
  31. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.  
  33. // Create labels and text fields //
  34.  
  35.  
  36. begBal = new JLabel("Beginning Balance: ");
  37. txtBegBal = new JTextField();
  38. txtBegBal.addActionListener(new BegBalListener());
  39.  
  40. cheAmt = new JLabel(" Check Amount: ");
  41. txtCheAmt = new JTextField();
  42. txtCheAmt.addActionListener(new CheAmtListener());
  43.  
  44. depAmt = new JLabel(" Deposit Amount: ");
  45. txtDepAmt = new JTextField();
  46. txtDepAmt.addActionListener(new DepAmtListener());
  47.  
  48. endBal = new JLabel(" Ending Balance: ");
  49. txtEndBal = new JTextField();
  50. txtEndBal.setEditable(false);
  51.  
  52. // Add all the components to the panel //
  53.  
  54. panel.add(begBal);
  55. panel.add(txtBegBal);
  56. panel.add(cheAmt);
  57. panel.add(txtCheAmt);
  58. panel.add(depAmt);
  59. panel.add(txtDepAmt);
  60. panel.add(endBal);
  61. panel.add(txtEndBal);
  62.  
  63. // Set the layout for the frame, the preferred size for the panel, add the panel to the frame //
  64.  
  65. frame.getContentPane().setLayout(new FlowLayout());
  66. panel.setPreferredSize(new Dimension(225, 85));
  67. frame.add(panel);
  68. frame.getContentPane().setBackground(Color.ORANGE);
  69. frame.setSize(300, 300);
  70. frame.setVisible(true);
  71.  
  72.  
  73. }
  74.  
  75. class BegBalListener implements ActionListener {
  76. public void actionPerformed(ActionEvent event) {
  77. int num = Integer.parseInt(event.getActionCommand());
  78. txtBegBal.setText(" ");
  79. }
  80. }
  81.  
  82. class CheAmtListener implements ActionListener {
  83. public void actionPerformed(ActionEvent event) {
  84. int num = Integer.parseInt(event.getActionCommand());
  85.  
  86. }
  87. }
  88.  
  89. class DepAmtListener implements ActionListener {
  90. public void actionPerformed(ActionEvent event) {
  91. int num = Integer.parseInt(event.getActionCommand());
  92.  
  93. }
  94. }
  95. }
Add Comment
Please, Sign In to add comment