Bank
import java.sql.Date.*;
import javax.swing.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
import java.io.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.text.*;
import java.net.*;
class Bank extends JFrame {
private JTabbedPane tabbedPane;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JButton addbutton;
private JTextField field,field2,fie1,fie2,fie3,fiee1,fiee2,fiee3;
private String amm="";
private int amountt;
JTextArea display;
ObjectOutputStream output;
ObjectInputStream input;
Socket client;
public Bank()
{
setTitle( "Banking Program" );
setSize( 400, 300 );
setBackground( Color.gray );
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
createPage1();
createPage2();
createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Add Client", panel1 );
tabbedPane.addTab( "With Draw", panel2 );
tabbedPane.addTab( "Deposit", panel3 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public void createPage1() {
panel1 = new JPanel();
panel1.setLayout( null );
JLabel label1 = new JLabel( "Client ID:" );
label1.setBounds( 10, 15, 150, 20 );
panel1.add( label1 );
field = new JTextField();
field.setBounds( 60, 15, 80, 20 );
panel1.add( field );
JLabel label2 = new JLabel( "Name:" );
label2.setBounds( 10, 45, 150, 20 );
panel1.add( label2 );
field2 = new JTextField();
field2.setBounds( 60, 45, 150, 20 );
panel1.add( field2 );
addbutton = new JButton("Add");
addbutton.setBounds(100, 100, 90, 20 );
addbutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
client = new Socket ( InetAddress.getByName ( "202.134.238.3" ), 10000 );
output = new ObjectOutputStream ( client.getOutputStream() );
output.flush();
String mess =field.getText();
String mess1 =field2.getText();//kini sad....
field.setCaretPosition ( field.getText().length() );
output.writeObject(mess);
output.writeObject(mess1);//kini
field2.setCaretPosition ( field2.getText().length() );
output.flush();
// field.getText()+"','" + field2.getText()
field.setText("");
field2.setText("");
} catch (java.lang.Exception ex){
//ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Add is not Succesfull");
field.setText("");
field2.setText("");
}
}
});
panel1.add( addbutton);
}
public void createPage2() {
panel2 = new JPanel();
panel2.setLayout( null);
panel2.setBackground( Color.blue );
JLabel lab1 = new JLabel( "Client ID:" );
lab1.setBounds( 10, 15, 150, 20 );
panel2.add( lab1 );
fie1 = new JTextField();
fie1.setBounds( 60, 15, 80, 20 );
panel2.add( fie1 );
JLabel lab2 = new JLabel( "Name:" );
lab2.setBounds( 10, 45, 150, 20 );
panel2.add( lab2 );
fie2 = new JTextField();
fie2.setBounds( 60, 45, 150, 20 );
fie2.setEditable(false);
panel2.add( fie2 );
JLabel amount = new JLabel("Amount:");
amount.setBounds( 10, 70, 150, 20 );
panel2.add(amount);
fie3 = new JTextField();
fie3.setBounds( 60, 70, 150, 20 );
panel2.add(fie3);
fie1.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Bank";
Connection con = DriverManager.getConnection(url,"awing","awing");
Statement st = con.createStatement();
String query1= "SELECT * FROM ClientTable WHERE Client_ID='"+fie1.getText()+"' ";
ResultSet rs1 = st.executeQuery(query1);
rs1.next();
fie2.setText(rs1.getString(2));
} catch (java.lang.Exception ex)
{
//ex.printStackTrace();
JOptionPane.showMessageDialog(null,"invalid Client ID or None in database");
}
}
});
JButton okbutton = new JButton("with draw");
okbutton.setBounds(100, 100, 90, 20 );
okbutton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
amm = fie3.getText();
amountt = Integer.parseInt(amm);
try {
} catch (java.lang.Exception ex)
{
//ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Add is not Succesfull");
}
}
});
panel2.add( okbutton);
}
public void createPage3()
{
panel3 = new JPanel();
panel3.setLayout( null );
panel3.setBackground( Color.orange );
JLabel labb1 = new JLabel( "Client ID:" );
labb1.setBounds( 10, 15, 150, 20 );
panel3.add( labb1 );
JTextField fiee1 = new JTextField();
fiee1.setBounds( 60, 15, 80, 20 );
panel3.add( fiee1 );
JLabel labb2 = new JLabel( "Name:" );
labb2.setBounds( 10, 45, 150, 20 );
panel3.add( labb2 );
JTextField fiee2 = new JTextField();
fiee2.setBounds( 60, 45, 150, 20 );
fiee2.setEditable(false);
panel3.add( fiee2 );
JLabel amoun = new JLabel("Amount:");
amoun.setBounds( 10, 70, 150, 20 );
panel3.add(amoun);
fiee3 = new JTextField();
fiee3.setBounds( 60, 70, 150, 20 );
panel3.add(fiee3);
JButton okkbutton = new JButton("deposit");
okkbutton.setBounds(100, 100, 90, 20 );
panel3.add( okkbutton);
}
// Main method to get things started
public static void main( String args[] )
{
// Create an instance of the test application
Bank mainFrame = new Bank();
mainFrame.setVisible( true );
}
}
No comments:
Post a Comment