Shloeb
04-08-2008, 01:21 PM
I am making a project on banking in JAVA.
I have created this code. But it has some flaws. I want to overcome that. Please help me remove them.
The database code is:
create table accinfo
(
caccno int,
cname varchar(15),
cfather varchar(15),
cdob varchar(10),
cgender varchar(8),
cacctype varchar(7),
cadd varchar(30),
city varchar(10),
cph int,
cbal int
)
SELECT * FROM accinfo
The program code is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class loginEx
{
JPanel p1,p2;
JFrame f;
TextField t1;
TextField t2;
JLabel l1,l2,l3,l4;
JTextField name,address,ph,birth,city,father,accno,balance,t3 ,t4,t5,t6,t7;
JButton login,exit,create,transac,check,close,back;
String dk,r2,r3,r5,r6,r7,r8;
int r1,r4,r9;
Choice gender,acctype;
public loginEx()
{
f=new JFrame("Login ");
p1=new JPanel();
p2=new JPanel();
t1=new TextField(20);
t2=new TextField(20);
f.getContentPane();
l1=new JLabel("Username:");
l2=new JLabel("Password:");
login=new JButton("Login");
login.addActionListener(new MainEx());
exit=new JButton("Exit");
exit.addActionListener(new MainEx());
l3=new JLabel("STATE BANK");
l4=new JLabel("OF INDIA");
l3.setFont(new Font("Times New Roman",Font.BOLD,50));
l4.setFont(new Font("Times New Roman",Font.BOLD,50));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,2,20,50));
p2.setLayout(new GridLayout(4,2,20,20));
p1.add(l3);
p1.add(l4);
p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
t2.setEchoChar('*');
p2.add(login);
p2.add(exit);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
public static void main(String sr[])
{
loginEx e=new loginEx();
}
/*-------------------------
Class Main Menu
---------------------------
*/
class MainEx extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s=="Login")
{
String i=t1.getText();
String j=t2.getText();
String k="a";
String m="a";
if(i.equals(k) && j.equals(m))
{
JFrame f=new JFrame("Main Menu");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
f=new JFrame("MENU");
JLabel l1;
f.getContentPane();
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,1,0,0));
p2.setLayout(new GridLayout(1,4,30,30));
l1=new JLabel("Select Your Choice");
l1.setFont(new Font("Times New Roman",Font.ITALIC,50));
create=new JButton("Create an Account");
create.addActionListener(new Form());
transac=new JButton("Transactions");
transac.addActionListener(new Transactions());
check=new JButton("Check Balance");
check.addActionListener(new ChkBal());
close=new JButton("Close Account");
close.addActionListener(new Close());
back=new JButton("Back");
p1.add(l1);
p2.add(create);
p2.add(transac);
p2.add(check);
p2.add(close);
p2.add(back);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
if(s=="Exit")
{
System.exit(0);
}
}
}
/*-----------------------------------------------------------
FORM
-------------------------------------------------------------
*/
class Form extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
JFrame f;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l;
JPanel p;
JButton submit,back;
f=new JFrame("Form");
p=new JPanel();
f.getContentPane();
f.setLayout(new FlowLayout(FlowLayout.LEFT,50,50));
p.setLayout(new GridLayout(11,2,30,30));
name=new JTextField(15);
address=new JTextField(30);
ph=new JTextField(15);
birth=new JTextField(8);
city=new JTextField(10);
father=new JTextField(15);
accno=new JTextField(8);
balance=new JTextField(10);
gender=new Choice();
acctype=new Choice();
gender.add("<Select>");
gender.add("Male");
gender.add("Female");
acctype.add("<Select>");
acctype.add("Savings");
acctype.add("Current");
l1=new JLabel("Name:");
l2=new JLabel("Father's Name:");
l3=new JLabel("Date of Birth:");
l4=new JLabel("Gender:");
l5=new JLabel("Account Type:");
l6=new JLabel("Address:");
l7=new JLabel("City:");
l8=new JLabel("Phone no:");
l9=new JLabel("Account no:");
l=new JLabel("Initial Balance:");
submit=new JButton("Submit");
submit.addActionListener(new rx());
back=new JButton("Back");
back.addActionListener(new MainEx());
p.add(l9);
p.add(accno);
p.add(l1);
p.add(name);
p.add(l2);
p.add(father);
p.add(l3);
p.add(birth);
p.add(l4);
p.add(gender);
p.add(l5);
p.add(acctype);
p.add(l6);
p.add(address);
p.add(l7);
p.add(city);
p.add(l8);
p.add(ph);
p.add(l);
p.add(balance);
p.add(submit);
p.add(back);
f.add(p);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*-----------------------------------------------------------------
SUBMIT INFO
-------------------------------------------------------------------
*/
class rx extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("INSERT INTO accinfo VALUES(?,?,?,?,?,?,?,?,?,?)");
int r1=Integer.parseInt(accno.getText());
String r2=name.getText();
String r3=father.getText();
int r4=Integer.parseInt(birth.getText());
String r5=gender.getSelectedItem().toString();
String r6=acctype.getSelectedItem().toString();
String r7=address.getText();
String r8=city.getText();
int r9=Integer.parseInt(ph.getText());
int r10=Integer.parseInt(balance.getText());
stat.setInt(1,r1);
stat.setString(2,r2);
stat.setString(3,r3);
stat.setInt(4,r4);
stat.setString(5,r5);
stat.setString(6,r6);
stat.setString(7,r7);
stat.setString(8,r8);
stat.setInt(9,r9);
stat.setInt(10,r10);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*-----------------------------------------------------------------
TRANSACTIONS
-------------------------------------------------------------------
*/
class Transactions extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JPanel p1,p2;
JButton dep,wid;
JLabel l;
f=new JFrame("Transactions");
p1=new JPanel();
p2=new JPanel();
l=new JLabel("Select Your Choice");
f.getContentPane();
dep=new JButton("Deposit");
dep.addActionListener(new Deposit());
wid=new JButton("Withdraw");
wid.addActionListener(new Withdraw());
l.setFont(new Font("Times New Roman",Font.ITALIC,50));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(1,2,30,30));
p1.add(l);
p2.add(dep);
p2.add(wid);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
DEPOSIT
-----------------------------------------------------------
*/
class Deposit extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2,l3;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Deposit");
accno=new JTextField(12);
balance=new JTextField(10);
l1=new JLabel("Account Number:");
l2=new JLabel("Amount:");
l3=new JLabel("Enter your account number and amount you want to deposit");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new deupd());
b2=new JButton("Back");
l3.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(3,2,30,30));
p1.add(l3);
p2.add(l1);
p2.add(accno);
p2.add(l2);
p2.add(balance);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
WITHDRAW
-----------------------------------------------------------
*/
class Withdraw extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2,l3;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Withdraw");
accno=new JTextField(12);
balance=new JTextField(10);
l1=new JLabel("Account Number:");
l2=new JLabel("Amount:");
l3=new JLabel("Enter your account number and the amount you want to withdraw");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new wideupd());
b2=new JButton("Back");
l3.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(3,2,30,30));
p1.add(l3);
p2.add(l1);
p2.add(accno);
p2.add(l2);
p2.add(balance);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
DEPOSIT UPDATE AMOUNT
-----------------------------------------------------------
*/
class deupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("update accinfo set cbal=cbal+? WHERE caccno=? ");
int r1=Integer.parseInt(accno.getText());
int r2=Integer.parseInt(balance.getText());
stat.setInt(1,r2);
stat.setInt(2,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*---------------------------------------------------------
WITHDRAW UPDATE AMOUNT
-----------------------------------------------------------
*/
class wideupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("update accinfo set cbal=cbal-? WHERE caccno=?");
int r1=Integer.parseInt(accno.getText());
int r2=Integer.parseInt(balance.getText());
stat.setInt(1,r2);
stat.setInt(2,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*---------------------------------------------------------
CHECK BALANCE
-----------------------------------------------------------
*/
class ChkBal extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Check Balance");
accno=new JTextField(12);
l1=new JLabel("Account Number:");
l2=new JLabel("Please enter your account number");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b2=new JButton("Back");
l2.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p2.setLayout(new GridLayout(2,2,30,30));
p1.add(l2);
p2.add(l1);
p2.add(accno);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*-------------------------------
INVALID USERNAME/PASSWORD
--------------------------------
class Invalid extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f=new JFrame("Error!!");
f.setLayout(new GridLayout(2,1,10,10));
JLabel l1=new JLabel("Please enter correct Username and password");
JButton b1=new JButton("Ok");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p2.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p1.add(l1);
p2.add(b1);
f.add(p1);
f.add(p2);
f.setSize(300,150);
f.setVisible(true);
}
}
*/
/*----------------------------------------
CLOSE ACCOUNT
------------------------------------------
*/
class Close extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Close Account");
accno=new JTextField(12);
l1=new JLabel("Account Number:");
l2=new JLabel("Please enter your account number");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new Closeupd());
b2=new JButton("Back");
l2.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p2.setLayout(new GridLayout(2,2,30,30));
p1.add(l2);
p2.add(l1);
p2.add(accno);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*----------------------------------------
CLOSE UPDATE
------------------------------------------
*/
class Closeupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("DELETE FROM accinfo WHERE caccno=?");
int r1=Integer.parseInt(accno.getText());
stat.setInt(1,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
}
I want these features to be in the project.
- When a new frame is created then the previous frame gets closed.
- When i click on the "Back" button then the previous frame is opened.
- When someone enters invalid username/password then Lable or a pop-up window gets opened tellling that u have entered a invalid username/password. When i press ok then it gets closed.
- When a new account is created then a pop-up window gets opened telling that "Account has been created" When i press "Ok" then Main Menu gets opened.
Please suggest something more to improve this project. If its possible for u then please edit this program and make it better. Thank You. :D
Any volunteer to help me out??
I have created this code. But it has some flaws. I want to overcome that. Please help me remove them.
The database code is:
create table accinfo
(
caccno int,
cname varchar(15),
cfather varchar(15),
cdob varchar(10),
cgender varchar(8),
cacctype varchar(7),
cadd varchar(30),
city varchar(10),
cph int,
cbal int
)
SELECT * FROM accinfo
The program code is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class loginEx
{
JPanel p1,p2;
JFrame f;
TextField t1;
TextField t2;
JLabel l1,l2,l3,l4;
JTextField name,address,ph,birth,city,father,accno,balance,t3 ,t4,t5,t6,t7;
JButton login,exit,create,transac,check,close,back;
String dk,r2,r3,r5,r6,r7,r8;
int r1,r4,r9;
Choice gender,acctype;
public loginEx()
{
f=new JFrame("Login ");
p1=new JPanel();
p2=new JPanel();
t1=new TextField(20);
t2=new TextField(20);
f.getContentPane();
l1=new JLabel("Username:");
l2=new JLabel("Password:");
login=new JButton("Login");
login.addActionListener(new MainEx());
exit=new JButton("Exit");
exit.addActionListener(new MainEx());
l3=new JLabel("STATE BANK");
l4=new JLabel("OF INDIA");
l3.setFont(new Font("Times New Roman",Font.BOLD,50));
l4.setFont(new Font("Times New Roman",Font.BOLD,50));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,2,20,50));
p2.setLayout(new GridLayout(4,2,20,20));
p1.add(l3);
p1.add(l4);
p2.add(l1);
p2.add(t1);
p2.add(l2);
p2.add(t2);
t2.setEchoChar('*');
p2.add(login);
p2.add(exit);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
public static void main(String sr[])
{
loginEx e=new loginEx();
}
/*-------------------------
Class Main Menu
---------------------------
*/
class MainEx extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s=="Login")
{
String i=t1.getText();
String j=t2.getText();
String k="a";
String m="a";
if(i.equals(k) && j.equals(m))
{
JFrame f=new JFrame("Main Menu");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
f=new JFrame("MENU");
JLabel l1;
f.getContentPane();
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,1,0,0));
p2.setLayout(new GridLayout(1,4,30,30));
l1=new JLabel("Select Your Choice");
l1.setFont(new Font("Times New Roman",Font.ITALIC,50));
create=new JButton("Create an Account");
create.addActionListener(new Form());
transac=new JButton("Transactions");
transac.addActionListener(new Transactions());
check=new JButton("Check Balance");
check.addActionListener(new ChkBal());
close=new JButton("Close Account");
close.addActionListener(new Close());
back=new JButton("Back");
p1.add(l1);
p2.add(create);
p2.add(transac);
p2.add(check);
p2.add(close);
p2.add(back);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
if(s=="Exit")
{
System.exit(0);
}
}
}
/*-----------------------------------------------------------
FORM
-------------------------------------------------------------
*/
class Form extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
JFrame f;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l;
JPanel p;
JButton submit,back;
f=new JFrame("Form");
p=new JPanel();
f.getContentPane();
f.setLayout(new FlowLayout(FlowLayout.LEFT,50,50));
p.setLayout(new GridLayout(11,2,30,30));
name=new JTextField(15);
address=new JTextField(30);
ph=new JTextField(15);
birth=new JTextField(8);
city=new JTextField(10);
father=new JTextField(15);
accno=new JTextField(8);
balance=new JTextField(10);
gender=new Choice();
acctype=new Choice();
gender.add("<Select>");
gender.add("Male");
gender.add("Female");
acctype.add("<Select>");
acctype.add("Savings");
acctype.add("Current");
l1=new JLabel("Name:");
l2=new JLabel("Father's Name:");
l3=new JLabel("Date of Birth:");
l4=new JLabel("Gender:");
l5=new JLabel("Account Type:");
l6=new JLabel("Address:");
l7=new JLabel("City:");
l8=new JLabel("Phone no:");
l9=new JLabel("Account no:");
l=new JLabel("Initial Balance:");
submit=new JButton("Submit");
submit.addActionListener(new rx());
back=new JButton("Back");
back.addActionListener(new MainEx());
p.add(l9);
p.add(accno);
p.add(l1);
p.add(name);
p.add(l2);
p.add(father);
p.add(l3);
p.add(birth);
p.add(l4);
p.add(gender);
p.add(l5);
p.add(acctype);
p.add(l6);
p.add(address);
p.add(l7);
p.add(city);
p.add(l8);
p.add(ph);
p.add(l);
p.add(balance);
p.add(submit);
p.add(back);
f.add(p);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*-----------------------------------------------------------------
SUBMIT INFO
-------------------------------------------------------------------
*/
class rx extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("INSERT INTO accinfo VALUES(?,?,?,?,?,?,?,?,?,?)");
int r1=Integer.parseInt(accno.getText());
String r2=name.getText();
String r3=father.getText();
int r4=Integer.parseInt(birth.getText());
String r5=gender.getSelectedItem().toString();
String r6=acctype.getSelectedItem().toString();
String r7=address.getText();
String r8=city.getText();
int r9=Integer.parseInt(ph.getText());
int r10=Integer.parseInt(balance.getText());
stat.setInt(1,r1);
stat.setString(2,r2);
stat.setString(3,r3);
stat.setInt(4,r4);
stat.setString(5,r5);
stat.setString(6,r6);
stat.setString(7,r7);
stat.setString(8,r8);
stat.setInt(9,r9);
stat.setInt(10,r10);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*-----------------------------------------------------------------
TRANSACTIONS
-------------------------------------------------------------------
*/
class Transactions extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JPanel p1,p2;
JButton dep,wid;
JLabel l;
f=new JFrame("Transactions");
p1=new JPanel();
p2=new JPanel();
l=new JLabel("Select Your Choice");
f.getContentPane();
dep=new JButton("Deposit");
dep.addActionListener(new Deposit());
wid=new JButton("Withdraw");
wid.addActionListener(new Withdraw());
l.setFont(new Font("Times New Roman",Font.ITALIC,50));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(1,2,30,30));
p1.add(l);
p2.add(dep);
p2.add(wid);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
DEPOSIT
-----------------------------------------------------------
*/
class Deposit extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2,l3;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Deposit");
accno=new JTextField(12);
balance=new JTextField(10);
l1=new JLabel("Account Number:");
l2=new JLabel("Amount:");
l3=new JLabel("Enter your account number and amount you want to deposit");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new deupd());
b2=new JButton("Back");
l3.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(3,2,30,30));
p1.add(l3);
p2.add(l1);
p2.add(accno);
p2.add(l2);
p2.add(balance);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
WITHDRAW
-----------------------------------------------------------
*/
class Withdraw extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2,l3;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Withdraw");
accno=new JTextField(12);
balance=new JTextField(10);
l1=new JLabel("Account Number:");
l2=new JLabel("Amount:");
l3=new JLabel("Enter your account number and the amount you want to withdraw");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new wideupd());
b2=new JButton("Back");
l3.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new GridLayout(1,0,50,50));
p2.setLayout(new GridLayout(3,2,30,30));
p1.add(l3);
p2.add(l1);
p2.add(accno);
p2.add(l2);
p2.add(balance);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*---------------------------------------------------------
DEPOSIT UPDATE AMOUNT
-----------------------------------------------------------
*/
class deupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("update accinfo set cbal=cbal+? WHERE caccno=? ");
int r1=Integer.parseInt(accno.getText());
int r2=Integer.parseInt(balance.getText());
stat.setInt(1,r2);
stat.setInt(2,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*---------------------------------------------------------
WITHDRAW UPDATE AMOUNT
-----------------------------------------------------------
*/
class wideupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("update accinfo set cbal=cbal-? WHERE caccno=?");
int r1=Integer.parseInt(accno.getText());
int r2=Integer.parseInt(balance.getText());
stat.setInt(1,r2);
stat.setInt(2,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
/*---------------------------------------------------------
CHECK BALANCE
-----------------------------------------------------------
*/
class ChkBal extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Check Balance");
accno=new JTextField(12);
l1=new JLabel("Account Number:");
l2=new JLabel("Please enter your account number");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b2=new JButton("Back");
l2.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p2.setLayout(new GridLayout(2,2,30,30));
p1.add(l2);
p2.add(l1);
p2.add(accno);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*-------------------------------
INVALID USERNAME/PASSWORD
--------------------------------
class Invalid extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f=new JFrame("Error!!");
f.setLayout(new GridLayout(2,1,10,10));
JLabel l1=new JLabel("Please enter correct Username and password");
JButton b1=new JButton("Ok");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p2.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p1.add(l1);
p2.add(b1);
f.add(p1);
f.add(p2);
f.setSize(300,150);
f.setVisible(true);
}
}
*/
/*----------------------------------------
CLOSE ACCOUNT
------------------------------------------
*/
class Close extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame f;
JLabel l1,l2;
JPanel p1,p2;
JButton b1,b2;
f=new JFrame("Close Account");
accno=new JTextField(12);
l1=new JLabel("Account Number:");
l2=new JLabel("Please enter your account number");
p1=new JPanel();
p2=new JPanel();
b1=new JButton("Submit");
b1.addActionListener(new Closeupd());
b2=new JButton("Back");
l2.setFont(new Font("Times New Roman",Font.BOLD,30));
f.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p1.setLayout(new FlowLayout(FlowLayout.CENTER,50,50));
p2.setLayout(new GridLayout(2,2,30,30));
p1.add(l2);
p2.add(l1);
p2.add(accno);
p2.add(b1);
p2.add(b2);
f.add(p1);
f.add(p2);
f.setSize(1100,900);
f.setVisible(true);
}
}
/*----------------------------------------
CLOSE UPDATE
------------------------------------------
*/
class Closeupd extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dk=e.getActionCommand();
if(dk.equals("Submit"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:accinfo","","");
PreparedStatement stat=con.prepareStatement("DELETE FROM accinfo WHERE caccno=?");
int r1=Integer.parseInt(accno.getText());
stat.setInt(1,r1);
stat.executeUpdate();
con.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
}
I want these features to be in the project.
- When a new frame is created then the previous frame gets closed.
- When i click on the "Back" button then the previous frame is opened.
- When someone enters invalid username/password then Lable or a pop-up window gets opened tellling that u have entered a invalid username/password. When i press ok then it gets closed.
- When a new account is created then a pop-up window gets opened telling that "Account has been created" When i press "Ok" then Main Menu gets opened.
Please suggest something more to improve this project. If its possible for u then please edit this program and make it better. Thank You. :D
Any volunteer to help me out??