Saturday, November 26, 2016

Online Bill Payment using JAVA

This is the simple code for online bill payment portal using java. To run this code successfully, you will need itext.jar library file for pdf which is used in this code for pdf creation.
you can download this file from here.
extract this zip file in java >> bin folder and run following code.

=================  OnlineBillPay.java     ================ 
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class OnlineBillPay extends JFrame
{
JButton b1,b2;
JLabel l1,l2,l3,l4,l5;
TextField jtf1,jtf2;
    public OnlineBillPay()
    {
    setTitle("BillPay...Online Bill Payment Portal");
    setSize(385,310);
    setLocationRelativeTo(null);
        setResizable(false);
    setVisible(true);
    setLayout(new FlowLayout(FlowLayout.CENTER,100,10));
        Font f = new Font("Times New Roman",Font.BOLD,60);
    l1=new JLabel("PayBill\n");
        l1.setHorizontalAlignment(SwingConstants.CENTER);
        l1.setFont(f);
        l2 = new JLabel("Pay your Telephone Bill Online here...");
        l2.setForeground(Color.red);
    b1=new JButton("LOGIN");
    add(l1);
        add(l2);
        jtf1 = new TextField(10);jtf2 = new TextField(10);
        jtf2.setEchoChar('*');
        l3 = new JLabel("LOGIN_ID:");l4 = new JLabel("PASSWORD:");
        l5 = new JLabel("Click Below to Pay without Login");
        b2 = new JButton("PayDirect");
        add(l3);add(jtf1);add(l4);add(jtf2);add(b1);add(l5);add(b2);
    setSize(385,310);setSize(385,310);   
        b1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae) {
                String id = jtf1.getText();
                String pwd = jtf2.getText();
                if(id.equals("Admin") && pwd.equals("admin")) {
                    dispose();
                    new AnotherJFrame();
                }
                else {
                    jtf1.setText(null);jtf2.setText(null);
                    JOptionPane.showMessageDialog(rootPane, "Wrong LOGIN_ID and PASSWORD Combination", "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });  
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae) {
                dispose();
                new Payment();
            }
        });  
       }
    public static void main(String args[])
    {
    new OnlineBillPay();
    }
}

===================  Payment.java  ===================

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Payment extends JFrame implements ActionListener
{
    TextField t1,t2,t3,t4,t5,t6,t7;
    Demo d;
    public Payment()
    {
        super("Payment Portal");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(700,500);
        setLocationRelativeTo(null);
        setResizable(true);
        setVisible(true);
        JLabel l0 = new JLabel("Payment Details");
        Font f = new Font("Cambria",Font.BOLD,40);
        l0.setFont(f);
        JLabel l00 = new JLabel("       ");
        setLayout(new GridLayout(11,2));
        Choice type = new Choice();
        type.add("VISA");type.add("MasterCard");type.add("Rupay");
        JLabel l1 = new JLabel("Your Name :");
        JLabel l2 = new JLabel("Email Id :");
        JLabel l3 = new JLabel("Telephone Number :");
        JLabel l4 = new JLabel("Credit/Debit Card Number :");
        JLabel l5 = new JLabel("CVC Number :");
        JLabel l6 = new JLabel("Pin Number :");
        JLabel l7 = new JLabel("Card Type :");
        JLabel l9 = new JLabel("Amount :");
        JLabel l8 = new JLabel("NOTE* : All Fields are Mandotory");
        JLabel l10 = new JLabel("         ");
        Font f1 = new Font("Cambria",Font.BOLD,15);
        l8.setFont(f1);
        l8.setForeground(Color.red);
        t1 = new TextField(20);    t2 = new TextField(20);    t3 = new TextField(20);
        t4 = new TextField(20);    t5 = new TextField(20);    t6 = new TextField(20);
    t7 = new TextField(20);
        JButton jb1 = new JButton("SUBMIT"); JButton jb2 = new JButton("RESET");                add(l0);add(l00);add(l1);add(t1);add(l2);add(t2);add(l3);add(t3);add(l4);add(t4);add(l7);add(type);add(l5);
    add(t5);add(l6);add(t6);add(l9);add(t7);add(l8);add(l10);add(jb1);add(jb2);
    jb1.addActionListener(this);       jb2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
        String s = ae.getActionCommand();
        if(s.equals("SUBMIT"))
        {
            String s1 = t1.getText();String s2 = t2.getText();String s3 = t3.getText();
            String s4 = t4.getText();String s5 = t5.getText();String s6 = t6.getText();
            String s7 = t7.getText();
if(s1.length() == 0 || s2.length() == 0 || s3.length() == 0 || s4.length() == 0 || s5.length() == 0 || s6.length() == 0 || s7.length() == 0)
{
    JOptionPane.showMessageDialog(rootPane,"Please Fill all the Fields","Error",JOptionPane.ERROR_MESSAGE);
}
            else {
                d = new Receipt(s1,s2,s3,s4);
                this.setVisible(false);
            }
        }
        if(s.equals("RESET")) {
            t1.setText("");    t2.setText("");    t3.setText("");    t4.setText("");
            t5.setText("");    t6.setText("");    t7.setText("");
        }
    }
    public static void main(String args[]) {
        new Payment();
    }
}

=================   Receipt.java  ===================

import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.io.*;
public class Receipt extends JFrame implements ActionListener
{
    JLabel l1,l2,l3,l4,l5,l6,l7,l8;
        public Receipt(String x, String y, String z, String w)
    {
        super("Receipt");
        setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(600,400);
            setLocationRelativeTo(null);
            setResizable(false);
        setLayout(new GridLayout(5,1));
            l1 = new JLabel("Name: ");
            l2 = new JLabel(x);
                l3 = new JLabel("EMAIL ID: ");
            l4 = new JLabel(y);
            l5 = new JLabel("Telephone Number : ");
            l6 = new JLabel(z);
                l7 = new JLabel("Amount Received");
                l8 = new JLabel(w);
            add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);add(l8);
            JButton jb1 = new JButton("SAVE");
            JButton jb2 = new JButton("OK");
            add(jb1);add(jb2);
        jb1.addActionListener(this);
        jb2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
            String s = ae.getActionCommand();
            if(s.equals("OK"))
            System.exit(0);
            else {
                try {
                    Document document = new Document();
                    try {
                        PdfWriter.getInstance(document, new FileOutputStream ("sample.pdf"));
                    } catch (FileNotFoundException ex) {
                        System.out.println("File Can not be created");
                    }
                    document.open();
                    document.add(new Paragraph(".........................Payment Receipt........................."));
                    document.add(new Paragraph(l1.getText()+"  "+l2.getText()));
                    document.add(new Paragraph(l3.getText()+"  "+l4.getText()));
                    document.add(new Paragraph(l5.getText()+"  "+l6.getText()));
                    document.add(new Paragraph(l7.getText()+"  "+l8.getText()));
                    document.close();
                    this.setVisible(false);
                } catch (DocumentException ex) {
                    System.out.println("File Can not be Opened");
                }
            }
    }
}

===================OUTPUT===================






 



 

 


0 comments:

Post a Comment

    Translate

    Protected by Copyscape