Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rob Joost //
- // 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
- // with the panels dimensions until it fit nicely //
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Gui {
- public static void main(String[] args){
- Gui gui1 = new Gui();
- gui1.CheckBookBalance();
- }
- public void CheckBookBalance (){
- // Create the frame and panel //
- JFrame frame = new JFrame("Checkbook Balancing Program");
- JPanel panel = new JPanel();
- CheckingAccount check = new CheckingAccount(0,0);
- // Set the background color to orange, and use a grid layout of 4 by 2 //
- panel.setLayout(new GridLayout(4, 2));
- panel.setBackground(Color.orange);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // Create labels and text fields //
- JLabel begBal = new JLabel("Beginning Balance: ");
- JTextField txtBegBal = new JTextField();
- txtBegBal.addActionListener(new BegBalListener());
- JLabel cheAmt = new JLabel(" Check Amount: ");
- JTextField txtCheAmt = new JTextField();
- txtCheAmt.addActionListener(new CheAmtListener());
- JLabel depAmt = new JLabel(" Deposit Amount: ");
- JTextField txtDepAmt = new JTextField();
- txtDepAmt.addActionListener(new DepAmtListener());
- JLabel endBal = new JLabel(" Ending Balance: ");
- JTextField txtEndBal = new JTextField();
- txtEndBal.setEditable(false);
- // Add all the components to the panel //
- panel.add(begBal);
- panel.add(txtBegBal);
- panel.add(cheAmt);
- panel.add(txtCheAmt);
- panel.add(depAmt);
- panel.add(txtDepAmt);
- panel.add(endBal);
- panel.add(txtEndBal);
- // Set the layout for the frame, the preferred size for the panel, add the panel to the frame //
- frame.getContentPane().setLayout(new FlowLayout());
- panel.setPreferredSize(new Dimension(225, 85));
- frame.add(panel);
- frame.getContentPane().setBackground(Color.ORANGE);
- frame.setSize(300, 300);
- frame.setVisible(true);
- }
- class BegBalListener implements ActionListener {
- public void actionPerformed(ActionEvent event){
- int num = Integer.parseInt(event.getActionCommand());
- txtBegBal.setText(" ");
- }
- }
- class CheAmtListener implements ActionListener {
- public void actionPerformed(ActionEvent event){
- int num = Integer.parseInt(event.getActionCommand());
- }
- }
- class DepAmtListener implements ActionListener {
- public void actionPerformed(ActionEvent event){
- int num = Integer.parseInt(event.getActionCommand());
- }
- }
- }
Add Comment
Please, Sign In to add comment