Guest User

Untitled

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