Thursday, August 21, 2014

Water District

Assume you are an employee from Davao City Water District. You are then asked to develop a program that will accept bill payments in the company to cater more customer in a day faster.

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class LabExercise44 extends JFrame {

    private JPanel contentPane;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    LabExercise44 frame = new LabExercise44();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public LabExercise44() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 400, 230);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
       
        JLabel lblNewLabel = new JLabel("Davao City Water District");
        lblNewLabel.setBounds(10, 11, 146, 14);
        contentPane.add(lblNewLabel);
       
        JLabel lblEnterYourName = new JLabel("Enter Your Name:");
        lblEnterYourName.setBounds(10, 50, 126, 14);
        contentPane.add(lblEnterYourName);
       
        JLabel lblEnterYourPayment = new JLabel("Enter Your Payment:");
        lblEnterYourPayment.setBounds(10, 75, 126, 14);
        contentPane.add(lblEnterYourPayment);
       
        textField = new JTextField();
        textField.setBounds(146, 47, 129, 20);
        contentPane.add(textField);
        textField.setColumns(10);
       
        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(146, 72, 129, 20);
        contentPane.add(textField_1);
       
        JButton btnPay = new JButton("Pay");
        btnPay.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                textField.getText();
                textField_1.getText();
                textField_2.setText("Name:\t"+textField.getText());
                textField_3.setText("Paid:\t"+textField_1.getText());
                textField_4.setText("Thank you for paying!");
               
               
            }
        });
        btnPay.setBounds(285, 46, 89, 23);
        contentPane.add(btnPay);
       
        JButton button = new JButton("Clear");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                textField_3.setText("");
                textField_4.setText("");
               
            }
        });
        button.setBounds(285, 71, 89, 23);
        contentPane.add(button);
       
        textField_2 = new JTextField();
        textField_2.setBounds(79, 122, 222, 20);
        contentPane.add(textField_2);
        textField_2.setColumns(10);
       
        textField_3 = new JTextField();
        textField_3.setColumns(10);
        textField_3.setBounds(79, 142, 222, 20);
        contentPane.add(textField_3);
       
        textField_4 = new JTextField();
        textField_4.setColumns(10);
        textField_4.setBounds(79, 161, 222, 20);
        contentPane.add(textField_4);
       
    }
}

No comments:

Post a Comment

advertisement