Beruflich Dokumente
Kultur Dokumente
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import java.awt.event.KeyEvent;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.FlowLayout;
import java.sql.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
JFrame frame;
JMenuBar menubar;
JMenu mAccount,mTransaction;
JMenuItem miNew,miClose,miExit,miDeposit,miWithdraw;
JDesktopPane desktopPane;
JInternalFrame newAccount,closeAccount,depositAccount,withdrawAccount;
Toolkit toolKit;
Dimension dimension;
JLabel deposit_lbAccNo=null;
JTextField
tfAccNo,tfName,tfAmmount,close_tfAccNo,close_tfName,close_tfAmt,deposit_tfAccNo,deposit_tfName,
deposit_tfBal,deposit_tfAmt;
JTextField withdraw_tfAccNo,withdraw_tfName,withdraw_tfBal,withdraw_tfAmt;
BankSimulator()
frame.add(menubar);
mAccount.setMnemonic(KeyEvent.VK_A);
mTransaction = new JMenu("Transaction");
mTransaction.setMnemonic(KeyEvent.VK_T);
miNew.setMnemonic(KeyEvent.VK_N);
miClose.setMnemonic(KeyEvent.VK_O);
miExit.setMnemonic(KeyEvent.VK_F4);
mAccount.add(miNew);
mAccount.add(miClose);
mAccount.add(miExit);
mTransaction.add(miDeposit);
mTransaction.add(miWithdraw);
menubar.add(mAccount);
menubar.add(mTransaction);
frame.setJMenuBar(menubar);
desktopPane.setBackground(Color.RED);
toolKit = Toolkit.getDefaultToolkit(); // Toolkit is a abstract class in awt
dimension = toolKit.getScreenSize();
frame.add(desktopPane);
frame.setVisible(true);
frame.setBounds(0,0,800,600);
frame.addWindowListener(this);
miNew.addActionListener(this);
miClose.addActionListener(this);
miExit.addActionListener(this);
miDeposit.addActionListener(this);
miWithdraw.addActionListener(this);
//--------------------------------------------------------------------------
if(jFrame == frame)
frame.dispose();
jmi = (JMenuItem)ae.getSource();
if(jmi == miNew)
newAccount.setBounds(200,200,320,200);
newAccount.setLayout(new FlowLayout());
tfAccNo.setEditable(false);
tfAccNo.setColumns(20);
tfName.setColumns(20);
tfAmmount.setColumns(20);
newAccount.add(lbAccNo);
newAccount.add(tfAccNo);
newAccount.add(lbName);
newAccount.add(tfName);
newAccount.add(lbAmount);
newAccount.add(tfAmmount);
newAccount.add(create);
newAccount.add(cancel);
newAccount.add(close);
create.addActionListener(new InternalActionListener());
close.addActionListener(new InternalActionListener());
cancel.addActionListener(new InternalActionListener());
//---------------------------------------------------------------------------------
desktopPane.add(newAccount);
newAccount.setVisible(true);
try
int a = rs.getInt(1);
a = a+1;
tfAccNo.setText(""+a);
ConnectionClass.closed();
catch(Exception ex)
System.out.println ("-------------------------------"+ex);
ex.printStackTrace();
finally
try{ConnectionClass.closed();}
catch(Exception es){es.printStackTrace();}
//--------------------------------------------------------------------
if(jmi == miClose)
{
flag = true;
closeAccount.setBounds(200,200,320,200);
closeAccount.setLayout(new FlowLayout());
close_tfAccNo.setName("close_tfAccNo");
close_tfAccNo.setColumns(20);
// close_tfName.setEditable(false);
close_tfName.setColumns(20);
close_tfAmt.setEditable(false);
close_tfAmt.setColumns(20);
closeAccount.add(close_tfAccNo);
closeAccount.add(lbName);
closeAccount.add(close_tfName);
closeAccount.add(lbAmt);
closeAccount.add(close_tfAmt);
closeAccount.add(close_button_yes);
closeAccount.add(close_button_no);
closeAccount.add(close_button_close);
close_tfAccNo.addActionListener(new InternalActionListener());
close_button_yes.addActionListener(new InternalActionListener());
close_button_no.addActionListener(new InternalActionListener());
close_button_close.addActionListener(new InternalActionListener());
//- --------------------------------------------------------------------------------
desktopPane.add(closeAccount);
closeAccount.setVisible(true);
if(jmi == miDeposit)
{
flag2 = true;
depositAccount.setBounds(200,200,320,200);
depositAccount.setLayout(new FlowLayout());
deposit_tfAccNo.setColumns(20);
deposit_tfAccNo.setName("deposit_tfAccNo");
deposit_tfName.setColumns(20);
deposit_tfName.setEditable(false);
deposit_tfBal.setColumns(20);
deposit_tfBal.setEditable(false);
deposit_tfAmt.setColumns(20);
depositAccount.add(lbAccNo);
depositAccount.add(deposit_tfAccNo);
depositAccount.add(lbName);
depositAccount.add(deposit_tfName);
depositAccount.add(lbBal);
depositAccount.add(deposit_tfBal);
depositAccount.add(lbAmt);
depositAccount.add(deposit_tfAmt);
depositAccount.add(deposit_button_update);
depositAccount.add(deposit_button_cancel);
depositAccount.add(deposit_button_close);
deposit_tfAccNo.addActionListener(new InternalActionListener());
deposit_button_update.addActionListener(new InternalActionListener());
deposit_button_cancel.addActionListener(new InternalActionListener());
deposit_button_close.addActionListener(new InternalActionListener());
//- --------------------------------------------------------------------------------
desktopPane.add(depositAccount);
depositAccount.setVisible(true);
}
if(jmi == miWithdraw)
withdrawAccount.setBounds(200,200,320,200);
withdrawAccount.setLayout(new FlowLayout());
withdraw_tfAccNo.setColumns(20);
withdraw_tfName.setColumns(20);
withdraw_tfName.setEditable(false);
withdraw_tfBal.setColumns(20);
withdraw_tfBal.setEditable(false);
withdraw_tfAmt.setColumns(20);
withdrawAccount.add(lbAccNo);
withdrawAccount.add(withdraw_tfAccNo);
withdrawAccount.add(lbName);
withdrawAccount.add(withdraw_tfName);
withdrawAccount.add(lbBal);
withdrawAccount.add(withdraw_tfBal);
withdrawAccount.add(lbAmt);
withdrawAccount.add(withdraw_tfAmt);
withdrawAccount.add(withdraw_button_update);
withdrawAccount.add(withdraw_button_cancel);
withdrawAccount.add(withdraw_button_close);
withdraw_tfAccNo.addActionListener(new InternalActionListener());
withdraw_button_update.addActionListener(new InternalActionListener());
withdraw_button_cancel.addActionListener(new InternalActionListener());
withdraw_button_close.addActionListener(new InternalActionListener());
//--------------------------------------------------------------------------
desktopPane.add(withdrawAccount);
withdrawAccount.setVisible(true);
if(jmi == miExit)
frame.dispose();
//------------------------------------------------------------------------
// int id = e.getID();
if(e.getSource().getClass().toString().equals("class javax.swing.JButton"))
button = (JButton)e.getSource();
if(e.getSource().getClass().toString().equals("class javax.swing.JTextField"))
textField = (JTextField)e.getSource();
if(button!=null)
if(button.getText().equals("Create"))
try
{
account+"','"+ammount+"')";
stmt.execute(query);
catch(Exception ex)
System.out.println ("hello"+ex);
finally
try{ConnectionClass.closed();}
catch(Exception ex){}
System.out.println (j);
if(j==0)
newAccount.dispose();
}
if(button.getText().equals("Cancel"))
System.out.println("I m in Cancle");
tfAmmount.setText("");
tfName.setText("");
if(button.getText().equals("Close") || button.getText().equals("CLOSE"))
System.out.println("I m in Close");
if(button.getText().equals("Close"))
if(newAccount != null)
newAccount.dispose();
depositAccount.dispose();
if(button.getText().equals("CLOSE"))
closeAccount.dispose();
}
if(button.getText().equals("Close."))
withdrawAccount.dispose();
if(button.getText().equals("YES"))
try
System.out.println (accno);
int j = JOptionPane.showConfirmDialog(null,"Account
Closed","",JOptionPane.PLAIN_MESSAGE);
if(j==0)
closeAccount.dispose();
catch(Exception ex)
{
System.out.println ("-------------------------------"+ex);
ex.printStackTrace();
finally
try{ConnectionClass.closed();}
catch(Exception es){es.printStackTrace();}
if(button.getText().equals("NO"))
JOptionPane.showMessageDialog(null,"dfdf");
closeAccount.dispose();
if(button.getText().equals("Update"))
try
System.out.println (b);
if(b==false)
System.out.println ("");
depositAccount.dispose();
ConnectionClass.closed();
catch(SQLException sqe)
sqe.printStackTrace();
// ConnectionClass.closed();
if(button.getText().equals("Update."))
{
try
if(total<0)
total=0;
System.out.println (b);
if(b==false)
System.out.println ("");
withdrawAccount.dispose();
ConnectionClass.closed();
catch(SQLException sqe)
{
sqe.printStackTrace();
// ConnectionClass.closed();
if(textField!=null)
// System.out.println(close_tfAccNo);
// System.out.println(deposit_tfAmt);
if(close_tfAccNo != null)
// close_tfName.setEditable(false);
System.out.println(" @@@@
"+textField.getName().toString());
try
System.out.println (accno);
ResultSet rs = stmt.executeQuery("SELECT
Name,amount FROM banktable where accountNo='"+accno+"'");
close_tfName.setText("");
close_tfAmt.setText("");
if(rs.next())
System.out.println (name);
close_tfName.setText(name);
System.out.println
(rs.getInt("amount"));
close_tfAmt.setText(Integer.toString(amount));
ConnectionClass.closed();
catch(Exception ex)
System.out.println
("-------------------------------"+ex);
ex.printStackTrace();
}
finally
try{ConnectionClass.closed();}
catch(Exception es){es.printStackTrace();}
// flag2 false;
if(deposit_tfAccNo!=null)
try
System.out.println (accno);
ResultSet rs = stmt.executeQuery("SELECT
Name,amount FROM banktable where accountNo='"+accno+"'");
deposit_tfName.setText("");
deposit_tfAmt.setText("");
deposit_tfBal.setText("");
if(rs.next())
System.out.println (name);
deposit_tfName.setText(name);
System.out.println
(rs.getInt("amount"));
deposit_tfBal.setText(Integer.toString(amount));
ConnectionClass.closed();
catch(Exception ex)
System.out.println
("-------------------------------"+ex);
ex.printStackTrace();
finally
try{ConnectionClass.closed();}
catch(Exception es){es.printStackTrace();}
}
}
if(withdrawAccount != null)
try
System.out.println (accno);
ResultSet rs = stmt.executeQuery("SELECT
Name,amount FROM banktable where accountNo='"+accno+"'");
withdraw_tfName.setText("");
withdraw_tfBal.setText("");
withdraw_tfAmt.setText("");
if(rs.next())
System.out.println (name);
withdraw_tfName.setText(name);
System.out.println
(rs.getInt("amount"));
withdraw_tfBal.setText(Integer.toString(amount));
ConnectionClass.closed();
catch(Exception ex)
System.out.println
("-------------------------------"+ex);
ex.printStackTrace();
finally
try{ConnectionClass.closed();}
catch(Exception es){es.printStackTrace();}
}
}
new BankSimulator();
class ConnectionClass
static
try
Class.forName("com.mysql.jdbc.Driver");
catch(Exception e)
{
e.printStackTrace();
try
String url="jdbc:mysql://localhost:3306/bank";
con=DriverManager.getConnection(url,"root","root");
System.out.println("connection estbalish");
return con;
catch(Exception e)
e.printStackTrace();
return con;
{
con.close();