import java.rmi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BankClient extends JFrame implements ActionListener,ItemListener
{
static MyRemote1 obj;
JTextField t1,t2;
JButton b1;
JLabel l1,l2,l3;
JPanel p1,p2,p3,mp;
JComboBox cb;
int bal=0,amt=0;
public BankClient()
{
t1=new JTextField(20);
t2=new JTextField(20);
b1=new JButton("Do");
b1.addActionListener(this);
l1=new JLabel("Amount");
l2=new JLabel("Mode");
l3=new JLabel("Balance");
cb=new JComboBox();
cb.addItem("Deposit");
cb.addItem("Withdraw");
cb.addItemListener(this);
p1=new JPanel();
p1.add(l1);
p1.add(t1);
p2=new JPanel();
p2.add(l2);
p2.add(cb);
p2.add(b1);
p3=new JPanel();
p3.add(l3);
p3.add(t2);
mp=new JPanel(new GridLayout(3,1));
mp.add(p1);
mp.add(p2);
mp.add(p3);
Container ct=getContentPane();
ct.setLayout(new FlowLayout());
ct.add(mp);
setTitle("Demo");
setSize(400,400);
setVisible(true);
}
int l;
public void itemStateChanged(ItemEvent ie)
{
l=cb.getSelectedIndex();
}
public void actionPerformed(ActionEvent ae)
{
if(l==0)
{
try
{
amt=Integer.parseInt(t1.getText());
obj.deposit(amt);
bal=obj.getbalance();
t2.setText(""+bal);
}
catch(Exception e)
{
}
}
if(l==1)
{
try
{
amt=Integer.parseInt(t1.getText());
obj.withdraw(amt);
bal=obj.getbalance();
t2.setText(""+bal);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,"Balance is not enough.");
}
}
}
public static void main(String args[])
{
try
{
obj=(MyRemote1)Naming.lookup("rmi://localhost:1099/OBJ2");
System.out.println("Calling remote methods");
new BankClient();
}catch(Exception e)
{
System.out.println("Error in lookup"+e);
}
}
}import java.rmi.*;
import java.rmi.server.*;
public class BankServer extends UnicastRemoteObject implements MyRemote1
{
public BankServer(String nm)throws RemoteException
{
try
{
Naming.bind(nm,this);
System.out.println("Object binded here.......");
}catch(Exception e)
{
System.out.println("Error in binding"+e);
}
}
int bal=0;
public void deposit(int amt) throws RemoteException
{
bal=bal+amt;
}
public void withdraw(int amt) throws RemoteException
{
if(bal-amt<500 p=""> {
throw new RemoteException();
}else
{
bal=bal-amt;
}
}
public int getbalance() throws RemoteException
{
return (bal);
}
public static void main(String arg[])throws RemoteException
{
new BankServer("OBJ2");
System.out.println("Server started here");
}
}import java.rmi.*;
public class MyClient
{
public static void main(String arg[])
{
try
{
MyRemote obj=(MyRemote)Naming.lookup("rmi://localhost:1099/OBJ1");
System.out.println("Calling remote methods");
int a=20,b=5,c=0;
c=obj.add(a,b);
System.out.println("Addition of"+a+" and "+b+" is "+c);
c=obj.sub(a,b);
System.out.println("Substraction of"+a+" and "+b+" is "+c);
c=obj.multi(a,b);
System.out.println("Multiplication of"+a+" and "+b+" is "+c);
c=obj.div(a,b);
System.out.println("division of"+a+" and "+b+" is "+c);
}catch(Exception e)
{
System.out.println("Error in lookup"+e);
}
}
}import java.rmi.*;
public interface MyRemote extends Remote
{
public int add(int a,int b)throws RemoteException;
public int sub(int a,int b)throws RemoteException;
public int multi(int a,int b)throws RemoteException;
public int div(int a,int b)throws RemoteException;
}import java.rmi.*;
public interface MyRemote1 extends Remote
{
public void deposit(int amt)throws RemoteException;
public void withdraw(int amt)throws RemoteException;
public int getbalance()throws RemoteException;
}import java.rmi.*;
import java.rmi.server.*;
public class MyServer extends UnicastRemoteObject implements MyRemote
{
public MyServer(String nm)throws RemoteException
{
try{
Naming.bind(nm,this);
System.out.println("Object binded here.......");
}catch(Exception e)
{
System.out.println("Error in binding"+e);
}
}
public int add(int a,int b) throws RemoteException
{
return (a+b);
}
public int sub(int a,int b) throws RemoteException
{
return (a-b);
}
public int multi(int a,int b) throws RemoteException
{
return (a*b);
}
public int div(int a,int b) throws RemoteException
{
return (a/b);
}
public static void main(String arg[])throws RemoteException
{
new MyServer("OBJ1");
System.out.println("Server started here");
}
}import java.sql.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.util.*;
public class SalsClient extends JFrame implements ActionListener
{
static SalsRemote obj;
Connection con;
ResultSet rs;
Statement st;
ResultSetMetaData rsmd;
JLabel l1,l2;
JTable jtab;
JScrollPane jsp;
JTextField t1;
JButton b_execute;
JPanel p1,p2,mp;
Vector head,row,data;
public SalsClient()
{
l1=new JLabel("SQL");
l2=new JLabel("Details are");
t1=new JTextField(20);
b_execute=new JButton("Execute");
b_execute.addActionListener(this);
p1=new JPanel();
jtab=new JTable();
int vsp=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int hsp=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
jsp=new JScrollPane(jtab,vsp,hsp);
p1.add(l1);
p1.add(t1);
p1.add(b_execute);
p2=new JPanel();
p2.add(l2);
p2.add(jsp);
mp=new JPanel();
Container ct=getContentPane();
ct.add(p1,BorderLayout.NORTH);
ct.add(p2,BorderLayout.CENTER);
setTitle("Demo");
setSize(550,400);
setVisible(true);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:abc","scott","tiger");
JOptionPane.showMessageDialog(this,"Database Connected");
}catch(Exception e)
{
JOptionPane.showMessageDialog(this,"Error in connection"+e);
}
}
public Vector displayData(String query)
{
try{
st=con.createStatement();
rs=st.executeQuery(query);
rsmd=rs.getMetaData();
int cols=rsmd.getColumnCount();
head=new Vector();
for(int i=1;i<=cols;i++)
{
head.add(rsmd.getColumnName(i));
}
data=new Vector();
data.add(head);
while(rs.next())
{
row=new Vector();
for(int i=1;i<=cols;i++)
{
row.add(rs.getString(i));
}
data.add(row);
}
}catch(Exception e)
{
head=new Vector();
head.add("No data found");
data=new Vector();
data.add(head);
}
return data;
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b_execute)
{
obj.
}
}
public static void main(String arg[])
{
try
{
obj=(SalsRemote)Naming.lookup("rmi://localhost:1099/OBJ3");
System.out.println("Calling remote methods");
new SalsClient();
}
catch{}
}
}
import java.rmi.*;
public interface SalRemote extends Remote
{
public vector getData(String query) throws RemoteException;
}500>
No comments:
Post a Comment