63
1.1)JAVA STARTER-SIMPLE ARITHMETIC Source: //simple arithmetic import java.io.*; import java.lang.*; class Sum { public static void main(String args[])throws IOException { int a,b,f; //float d,e,f; DataInputStream dis=new DataInputStream(System.in); System.out.println("Enter the two integers and float values"); a=Integer.parseInt(dis.readLine()); b=Integer.parseInt(dis.readLine()); //d=Float.parseFloat(dis.readLine()); //e=Float.parseFloat(dis.readLine()); f=a+b; System.out.println("sum of the numbers are"); System.out.println(f); } } IT1403: Software Components Lab

Cbt Lab Final Softcopy

  • Upload
    pathryr

  • View
    312

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Cbt Lab Final Softcopy

1.1)JAVA STARTER-SIMPLE ARITHMETIC

Source:

//simple arithmetic

import java.io.*;

import java.lang.*;

class Sum

{

public static void main(String args[])throws IOException

{

int a,b,f;

//float d,e,f;

DataInputStream dis=new DataInputStream(System.in);

System.out.println("Enter the two integers and float values");

a=Integer.parseInt(dis.readLine());

b=Integer.parseInt(dis.readLine());

//d=Float.parseFloat(dis.readLine());

//e=Float.parseFloat(dis.readLine());

f=a+b;

System.out.println("sum of the numbers are");

System.out.println(f);

}

}

IT1403: Software Components Lab

Page 2: Cbt Lab Final Softcopy

Input/output:

F:\lab exercise>javac Sum.java

Note: Sum.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

F:\lab exercise>java Sum

Enter the two integers values

10

20

sum of the numbers are

30

IT1403: Software Components Lab

Page 3: Cbt Lab Final Softcopy

2.2)INHERITANCE-MARK SHEET PREPARATION

Source:

//mark sheet

import java.io.*;class student //throws IOException {char name[]=new char[50];int regno;String q;void get() throws IOException{System.out.print("\nName :");DataInputStream dis=new DataInputStream(System.in);q=dis.readLine();System.out.print("\nReg No :");regno=Integer.parseInt(dis.readLine());}void put() throws IOException{System.out.print("\nName : " +q);System.out.println("\tReg No : "+regno);System.out.print("\nSemester : IV\tMIN : 50\tMAX : 100\n");}}class mark extends student{int m1,m2,m3,m4,tot1,tot2,a;float p1,p2;String res1,res2,res;void getdata() throws IOException{get();System.out.print("\nExternal mark (sub 1):");DataInputStream dis=new DataInputStream(System.in);m1=Integer.parseInt(dis.readLine());System.out.print("\nEnter internal mark (sub 1) :");m2=Integer.parseInt(dis.readLine());System.out.print("\nExternal mark (sub 2):");m3=Integer.parseInt(dis.readLine());System.out.print("\nEnter internal mark (sub 2):");m4=Integer.parseInt(dis.readLine());tot1=(m1+m2);tot2=(m3+m4);p1=tot1/2;p2=tot2/2;if(tot1>50)

IT1403: Software Components Lab

Page 4: Cbt Lab Final Softcopy

res1="pass";elseres1="fail";if(tot2>50)res2="pass";elseres2="fail";if(res1.equals("fail")||res2.equals("fail"))res="fail";elseres="pass";if(tot1<50)a++;if(tot2<50)a++;}void putdata() throws IOException{System.out.println("\n\tMARK SHEET\n");put();System.out.print("Code\tSub Name\tEXT\tINT\tTOT\tRESULT\n");System.out.print("IF 251\tMobile Comp\t"+m1+"\t"+m2+"\t"+(m1+m2)+"\t"+res1);System.out.print("\nIF 252\tComp Net\t"+m3+"\t"+m4+"\t"+(m3+m4)+"\t"+res2);System.out.println("\nResult : "+res+"\tPercentage : "+((tot1+tot2)/2));System.out.println("\nArrears : "+a);}}class Inherit{public static void main(String args[]) throws IOException{mark m=new mark();System.out.println("\nEnter student details \n");m.getdata();System.out.println("\n\n Student Marksheet \n");m.putdata();}}

IT1403: Software Components Lab

Page 5: Cbt Lab Final Softcopy

Input/output:

Z:\>javac Inherit.javaZ:\>java InheritEnter student details Name :dharunReg No :10External mark (sub 1):70Enter internal mark (sub 1) :20External mark (sub 2):65Enter internal mark (sub 2):20 Student Marksheet MARK SHEETName : dharun Reg No : 79Semester : VII MIN : 50 MAX : 100Code Sub Name EXT INT TOT RESULTIT 251 Mobile Comp 70 20 90 passIT 1001 UID 65 20 85 passResult : pass Percentage : 87Arrears : 0

IT1403: Software Components Lab

Page 6: Cbt Lab Final Softcopy

1.3)INTERFACE-CALCULATE NET SALARY OF EMPLOYEE

//net salary

import java.io.*;import java.lang.*;interface sri{

int hello(int gs,int d,int hra,int ta,int pf);}

class AB implements sri{

int ns;public int hello(int gs,int d,int hra,int ta,int pf){

ns=gs-d+hra+ta-pf;return ns;

}}class inter{

public static void main(String args[]){

sri s=new AB();AB a1=new AB();s=a1;int a,b,hra,pf,ta;DataInputStream in=new DataInputStream(System.in);try{

System.out.println("Enter Gross salary:");a=Integer.parseInt(in.readLine());System.out.println("HRA:");hra=Integer.parseInt(in.readLine());System.out.println("TA:");ta=Integer.parseInt(in.readLine());System.out.println("PF:");pf=Integer.parseInt(in.readLine());System.out.println("Enter Deduction:");b=Integer.parseInt(in.readLine());

System.out.println("Net Salary is:"+s.hello(a,b,hra,ta,pf));}catch(Exception e){

System.out.println("Error");}}}

IT1403: Software Components Lab

Page 7: Cbt Lab Final Softcopy

OutPut:

IT1403: Software Components Lab

Page 8: Cbt Lab Final Softcopy

1.4) PACKAGE – BANK APPLICATION

//bank application

package mypack;import java.io.*;import java.lang.*;

public class create{int acc_no=1001;int bal,amount1,amount,acc_n;String name;int am,acc,acc1;DataInputStream ds=new DataInputStream(System.in);public void createAccount()throws IOException{System.out.println("enter name:");name=ds.readLine();System.out.println(name+"your acc_no is"+acc_no);}public void DepositAmount()throws IOException{System.out.println("Enter u r account NO:");acc_n=Integer.parseInt(ds.readLine());if(acc_no==acc_n){System.out.println("Amount");amount1=Integer.parseInt(ds.readLine());amount=amount+amount1;System.out.println("the amount is:"+amount);System.out.println("the balence amount is:"+amount);}elseSystem.out.println("Enter correct account no");}public void withdrawal()throws IOException{System.out.println("enter your account number");acc=Integer.parseInt(ds.readLine());if(acc==acc_no){System.out.println("Enter the withdrawal amount");am=Integer.parseInt(ds.readLine());if(am>amount){System.out.println("Cannot with draw");}amount=amount-am;

IT1403: Software Components Lab

Page 9: Cbt Lab Final Softcopy

System.out.println("the balence amount is:"+amount);}elseSystem.out.println( "enter the correct account no:");}public void check_amount()throws IOException{System.out.println("enter the your account number");acc1=Integer.parseInt(ds.readLine());if(acc1==acc_no){System.out.println("balence amount "+amount);}elseSystem.out.println("enter the correct account no");}}

IT1403: Software Components Lab

Page 10: Cbt Lab Final Softcopy

//bank

import mypack.*;import java.io.*;import java.lang.*;class bank{public static void main(String args[])throws IOException{int i;create c =new create();DataInputStream dis= new DataInputStream(System.in);do{System.out.println("enter the ur choice 1.create account 2.depositing 3.withdrawal 4.check 5.exit");i=Integer.parseInt(dis.readLine());switch(i){case 1:c.createAccount();break;case 2:c.DepositAmount();break;case 3:c.withdrawal();break;case 4:c.check_amount();break;case 5:System.exit(0);}}while(true);}}

IT1403: Software Components Lab

Page 11: Cbt Lab Final Softcopy

Input/output:

c:\create>javac mypack.javaNote: pack.java uses or overrides a deprecated API.Note: Recompile with -Xlint:deprecation for details.c:\>javac bank.javac:\>java bank

IT1403: Software Components Lab

Page 12: Cbt Lab Final Softcopy

1.5) APPLET LAYOUT FOR CALCULATOR

Source:

//applet

import java.io.*;import java.applet.*;import java.awt.*;import java.awt.event.*;import java.lang.*;/*<applet code= "call1.class" width=500 height=500></applet>*/public class call1 extends Applet implements ActionListener {Label l1= new Label("number1");Label l2= new Label("number2");Label l3= new Label("result");TextField t1=new TextField(20);TextField t2=new TextField(20);TextField t3=new TextField(20);Button b1 =new Button ("ADD");Button b2 =new Button ("SUB");Button b3 =new Button ("MUL");Button b4 =new Button ("DIV");public void init(){add(l1);add(t1);add(l2);add(t2);add(l3);add(t3);add(b1);add(b2);add(b3);add(b4);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);}public void actionPerformed(ActionEvent e){int n1,n2,result;float result1;String s1=t1.getText();String s2=t2.getText();n1=Integer.parseInt(s1);n2=Integer.parseInt(s2);

IT1403: Software Components Lab

Page 13: Cbt Lab Final Softcopy

if(e.getSource()==b1){result=n1+n2;String s3=Integer.toString(result);t3.setText(s3);}if(e.getSource()==b2){result=n1-n2;String s3=Integer.toString(result);t3.setText(s3);}if(e.getSource()==b3){result=n1*n2;String s3=Integer.toString(result);t3.setText(s3);}if(e.getSource()==b4){result=n1/n2;String s3=Integer.toString(result);t3.setText(s3);}}}

IT1403: Software Components Lab

Page 14: Cbt Lab Final Softcopy

Execution Procedure:Compile java program.

C:\jdk1.5.0\bin> javac call1.java

C:\jdk1.5.0\bin>appletviewer call1.java

OutPut:

IT1403: Software Components Lab

Page 15: Cbt Lab Final Softcopy

2 .1)RMI-ARITHMETIC OPERATION

Source:

//program

\\CALCULATOR.JAVA:

import java.rmi.*;import java.rmi.RemoteException;public interface Calculator extends Remote{public long add(long a,long b)throws RemoteException;public long sub(long a,long b)throws RemoteException;public long mul(long a,long b)throws RemoteException;public long div(long a,long b)throws RemoteException;}

\\CALCULATORCLIENT.JAVA:

import java.rmi.Naming;import java.rmi.RemoteException;import java.rmi.*;public class CalculatorClient{public static void main (String args[]){try{Calculator c=(Calculator)Naming.lookup("//Localhost/CalculatorServername");System.out.println("sub 4,3 = "+c.sub(4,3));System.out.println("add 4,3 = "+c.add(4,3));System.out.println("mul 4,3 = "+c.mul(4,3));System.out.println("div 4,3 = "+c.div(4,3));}catch(Exception e){System.out.println("Err in client:"+e);}}}

IT1403: Software Components Lab

Page 16: Cbt Lab Final Softcopy

\\CALCULATORSERVER.JAVA:

import java.rmi.Naming;import java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject;public class CalculatorServer extends UnicastRemoteObject implements Calculator{public CalculatorServer()throws RemoteException{try{System.out.println("within constructor of server");}catch (Exception e){System.out.println("Trouble :"+e);}}public long add(long a,long b)throws RemoteException{return a+b;}public long div(long a,long b)throws RemoteException{return a/b;}public long sub(long a,long b)throws RemoteException{return a-b;}public long mul(long a,long b)throws RemoteException{return a*b;}public static void main(String Args[]){try{CalculatorServer cs=new CalculatorServer();Naming.rebind("DalculatorServername",cs);System.out.println("server is ready");}catch(Exception e){System.out.println("Trouble in Cal-server:"+e);}}}

IT1403: Software Components Lab

Page 17: Cbt Lab Final Softcopy

Output:

sub 4,3 = 1add 4,3 = 7mul 4,3 = 12div 4,3 = 1

IT1403: Software Components Lab

Page 18: Cbt Lab Final Softcopy

2.2)RMI- PALINDROME

Source:

//program

palininter.javaimport java.rmi.*;public interface palininter extends java.rmi.Remote{public String palin(String str) throws RemoteException;}

palinserver.javaimport java.rmi.*;import java.io.*;import java.rmi.server.UnicastRemoteObject;public class palinserver extends UnicastRemoteObject implements palininter{public palinserver() throws RemoteException{}public int l=0,s=0,j=0;public int len;public String palin(String str){l=0;len=0;j=0;len=str.length();for(int i=len-1;i>=0;i--){if(str.charAt(j)==str.charAt(i)){l=l+1;}j=j+1;}if(l==len){return("Palindrome");}else{return("not palindrom");}}public static void main(String ar[]){try{palinserver ob=new palinserver(); IT1403: Software Components Lab

Page 19: Cbt Lab Final Softcopy

Naming.rebind("pserver",ob);System.out.println("Connecting..........");}catch(Exception e){ }}};

palinclient.javaimport java.rmi.*;import java.io.*;public class palinclient{public static void main(String de[]){try{InputStreamReader obj=new InputStreamReader(System.in);BufferedReader ob1=new BufferedReader(obj);System.out.println("Enter teh input string");String s=ob1.readLine();palininter ob2=(palininter)Naming.lookup("pserver");System.out.println(ob2.palin(s));}catch(Exception e){System.out.println(e);}}};

IT1403: Software Components Lab

Page 20: Cbt Lab Final Softcopy

Execution Procedure:1. Compile all above three java program.

C:\jdk1.5.0\bin> javac palininter.javaC:\jdk1.5.0\bin> javac palinserver.javaC:\jdk1.5.0\bin> javac palinclient.java

2. Start rmiserver C:\jdk1.5.0\bin> rmic palinserver

3. Start rmiregistery C:\jdk1.5.0\bin> start rmiregistry

4. Open a new command window and execute the serverC:\jdk1.5.0\bin> java palinserver

5. Open a new command window and execute the clientC:\jdk1.5.0\bin> java palinclient

Output:C:\jdk1.5.0\bin> C:\jdk1.5.0\bin> Enter the String: Enter the String:Jothi malayalamNot palindrome palindrome

IT1403: Software Components Lab

Page 21: Cbt Lab Final Softcopy

2.3) RMI- HELLO WORLD

rmiiner.javaimport java.rmi.*;public interface rmiinter extends java.rmi.Remote{public String sayhello() throws RemoteException;}

rmiserver.javaimport java.io.*;import java.rmi.server.UnicastRemoteObject;import java.rmi.*;public class rmiserver extends UnicastRemoteObject implements rmiinter{public rmiserver() throws RemoteException{}public String sayhello(){return "Helloworld";}public static void main(String str[]){try{rmiserver ob=new rmiserver();Naming.rebind("rserver",ob);System.out.println("Connecting........");}catch(Exception e){ }}};

rmiclient.javaimport java.io.*;import java.rmi.*;public class rmiclient{public static void main(String str[]){try{rmiinter ob=(rmiinter) Naming.lookup("rserver");System.out.println(ob.sayhello());}catch(Exception e){}}}; IT1403: Software Components Lab

Page 22: Cbt Lab Final Softcopy

Execution Procedure:1. Compile all above three java program.

C:\jdk1.5.0\bin> javac rmiinter.javaC:\jdk1.5.0\bin> javac rmiserver.javaC:\jdk1.5.0\bin> javac rmiclient.java

2. Start rmiserver C:\jdk1.5.0\bin> rmic rmiserver

3. Start rmiregistery C:\jdk1.5.0\bin> start rmiregistry

4. Open a new command window and execute the serverC:\jdk1.5.0\bin> java rmiserver

5. Open a new command window and execute the clientC:\jdk1.5.0\bin> java rmiclient

Output :D:\jdk1.5.0\bin>HelloWorld

IT1403: Software Components Lab

Page 23: Cbt Lab Final Softcopy

3)CORBA- DEVELOPING A COMPONENT IN IDL

CODINGS:Interface

module myhelloworld { interface halo { string halo (); }; };

Implementationpackage myhelloworld;import org.omg.CORBA.*;public class Guday extends haloPOA { private String loc; guday (String loc) { this. loc=loc; } public String hello () { return "helloworld"+loc; } }

Serverpackage myhelloworld;import java.io.*;import org.omg.CORBA.*;import org.omg.Portable Server.*;public class server{ public static void main (String str []) { if (str.length! =1) { System.out.println ("usage: helloworld.server<location>"); System. exit (1); } try { ORB orb =ORB. init (str, null); POA poa= POAHelper.narrow (orb.resolve_initial_references ("RootPOA")); poa.the_POAManager ().activate (); guday goodDayimpl= new guday (str [0]); org.omg.CORBA.Object obj=poa.servant_to_reference (goodDayImpl);

IT1403: Software Components Lab

Page 24: Cbt Lab Final Softcopy

FileWriter Out=new FileWriter ("ior"); Out.write (orb.object_to_String (obj)); out.close (); orb.run (); } catch (System Exception e) { e.printStackTrace (); } catch (java.lang.Exception ie) { System.err.println (ie); } } }

Clientpackage myhelloworld;import java.io.*;import org.omg.CORBA.*;public class client { public static void main (String args []) { try { ORB.orb=ORB.init (args, null); String ior; if (args.length==1) { ior = args [0]; } else { ior = new BufferedReader (new FileReader ("ior")).readLine (); } org.omg.CORBA.Object obj=orb.string_to_object (ior); halo goodday=haloHelper.narrow (obj); if (goodday==null) { System.out.println ("Stringified IOR is not of type goodday); System. exit (1); } System.out.println (goodday.halo ()); } catch (System Exception ex) { System.out.println (ex); } catch (IOException ex) { System.error.println (ex); } } }

IT1403: Software Components Lab

Page 25: Cbt Lab Final Softcopy

OUTPUT:

IT1403: Software Components Lab

Page 26: Cbt Lab Final Softcopy

4)EJB APPLICATION IN J2EE SERVERSource:

Add remote .Java

import javax.ejb.*;

import java.rmi.*;

public interface addremote extends EJBObject

{

public int add(int a, int b) throws RemoteException;

}

Addbean.Java

import javax.ejb.*;

import java.rmi.*;

public class addbean implements SessionBean

{

public int add(int a,int b) throws RemoteException

{

return a+b;

}

public void ejbCreate() { }

public void ejbRemove() { }

public void ejbActivate() { }

public void ejbPassivate() { }

public void setSessionContext(SessionContext ct)

{

}

}

IT1403: Software Components Lab

Page 27: Cbt Lab Final Softcopy

Addhome.Java

import javax.ejb.*;

import java.rmi.*;

public interface addhome extends EJBHome

{

addremote create() throws RemoteException, CreateException;

}

Addclient.Java

import javax.naming.Context;

import java.io.*;

import javax.naming.InitialContext;

import javax.rmi.PortableRemoteObject;

public class addclient

{

public static void main(String s[])

{

try

{

Context initial=new InitialContext();

Object objref=initial.lookup("add");

addhome ah=(addhome)PortableRemoteObject.narrow(objref, addhome.class);

addremote ar=ah.create();

System.out.println(ar.add(5,5));

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

IT1403: Software Components Lab

Page 28: Cbt Lab Final Softcopy

DEPLOYMENT SCREEN

IT1403: Software Components Lab

Page 29: Cbt Lab Final Softcopy

APPLICATION CLIENT SCREEN

IT1403: Software Components Lab

Page 30: Cbt Lab Final Softcopy

OUTPUT SCREEN

IT1403: Software Components Lab

Page 31: Cbt Lab Final Softcopy

5)DATABASE- SIMPLE JDBC ODBC APPLICATION

Source:

import java.sql.*;

public class jdbc{public static void main(String s[]){Connection con;Statement stmt;String url="jdbc:odbc:dsn";try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.err.println("ClassNotFoundException :"+e.getMessage());}try{con=DriverManager.getConnection(url);stmt=con.createStatement();String st = "insert into tbl values('a',23)";stmt.executeUpdate(st);

ResultSet rs = stmt.executeQuery("select * from tbl");while(rs.next()){System.out.println("Name : " + rs.getObject(1) +" Age:"+rs.getObject(2));}rs.close();

stmt.close();con.close();}catch(SQLException ex){System.err.println("SQLException :"+ex.getMessage());}}}

IT1403: Software Components Lab

Page 32: Cbt Lab Final Softcopy

OUTPUT

IT1403: Software Components Lab

Page 33: Cbt Lab Final Softcopy

6.1)WORKING WITH GENERIC SERVLET

Program:

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class myservlet extends GenericServlet

{

public void service(ServletRequest req,ServletResponse res)throws IOException,ServletException

{

//String str=req.getParameter("name");

PrintWriter pw=res.getWriter();

pw.println("<html>");

pw.println("hello");

pw.println("</html>");

pw.close();

}

}

To run:

Compile the java file by specifying following command F:\lab

exercise\color>javac -classpath C:\Jsdk2.0\lib\jsdk.jar myservlet.java and then copy the class file

into the C:\Jsdk2.0\examples directory.

To see the output open the IE and type the URL as http://localhost:8080/servlet/myservlet.

IT1403: Software Components Lab

Page 34: Cbt Lab Final Softcopy

Output:

IT1403: Software Components Lab

Page 35: Cbt Lab Final Softcopy

6.2)WORKING WITH HTTP SERVLET

Program:

//Java – program:

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class color extends HttpServlet

{

public void doGet(HttpServletRequest req, HttpServletResponse res)throws

IOException,ServletException

{

try

{

String color=req.getParameter("color");

res.setContentType("text/html");

PrintWriter pw=res.getWriter();

pw.println("selected color is"+color);

pw.println(color);

pw.close();

}

catch(Exception e)

{}

}

}

//HTML-Program:

IT1403: Software Components Lab

Page 36: Cbt Lab Final Softcopy

<html>

<title>color</title>

<body>

<form name = "f1"action="http://localhost:8080/servlet/color">

<b> color</b>

<select name ="color",size="1">

<option value ="red">red</option>

<option value ="green">green</option>

<option value ="blue">blue</option>

</select>

<input type="submit">

</form>

</body>

</html>

To run:

* Compile the java file by specifying following command

F:\lab exercise\color>javac -classpath C:\Jsdk2.0\lib\jsdk.jar color.java

And then copy the class file into the C:\Jsdk2.0\examples directory.

*Open another command prompt and set the path as F:\>set path=%path%;C:\Jsdk2.0\bin and

then start servlet runner by specifying

F:\>servletrunner

servletrunner starting with settings:

port = 8080

backlog = 50

max handlers = 100

timeout = 5000

servlet dir = .\examples

document dir = .\examples

servlet propfile = .\examples\servlet.properties

*Open the HTML page and click submit to see the result.

IT1403: Software Components Lab

Page 37: Cbt Lab Final Softcopy

OUTPUT

IT1403: Software Components Lab

Page 38: Cbt Lab Final Softcopy

6.3)DICTIONARY SEARCH USING SERVLET RUNNER

//program

Client.html

<html><body><form name="dictionary" action="http://localhost:8080/servlet/dict1"><input type=text name="word" value=""><input type=submit value="submit"></form></body></html>

dict1.java

import java.io.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class dict1 extends HttpServlet

{

public void doGet(HttpServletRequest req,HttpServletResponse res) throws

ServletException,IOException

{

String word =req.getParameter("word");

PrintWriter pw;

TreeMap tm=new TreeMap();

res.setContentType("text/html");

pw=res.getWriter();

tm.put("conflict","difference");

tm.put("example","instance");

tm.put("contrast","tender");

Set set=tm.entrySet();

Iterator i=set.iterator();

Map.Entry me;

String s=" ";

while(i.hasNext())

IT1403: Software Components Lab

Page 39: Cbt Lab Final Softcopy

{

me=(Map.Entry)i.next();

if(me.getKey().equals(word))

{

s=me.getValue().toString();

}

}

pw.println("answer is");

pw.println(s);}}

IT1403: Software Components Lab

Page 40: Cbt Lab Final Softcopy

OUTPUT:

IT1403: Software Components Lab

Page 41: Cbt Lab Final Softcopy

7.1)WORKING WITH BUILT IN BEANS

IT1403: Software Components Lab

Page 42: Cbt Lab Final Softcopy

7.2)CREATING CUSTOMISED BEANS

BEAN.MFT:

Name: draw.class

Java-Bean: True

DRAW.JAVA:

import java.awt.*;

import java.awt.event.*;

import java.io.*;

public class draw extends Canvas implements Serializable

{

transient private Color c;

private boolean rectangular;

public draw()

{

addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent me)

{

change();

}

});

rectangular =false;

setSize(200,100);

change();

}

public boolean getRectangular()

{

return rectangular;

}

IT1403: Software Components Lab

Page 43: Cbt Lab Final Softcopy

public void setRectangular(boolean flag)

{

this.rectangular=flag;

repaint();

}

public void change()

{

c=randomColor();

repaint();

}

private Color randomColor()

{

int r=(int) (255*Math.random());

int g=(int) (255*Math.random());

int b=(int) (255*Math.random());

return new Color(r,g,b);

}

public void paint(Graphics g)

{

Dimension d=getSize();

int h=d.height;

int w=d.width;

g.setColor(c);

if(rectangular)

{

g.fillRect(0,0,w-1,h-1);

}

else

{

g.fillOval(0,0,w-1,h-1);

} } }

IT1403: Software Components Lab

Page 44: Cbt Lab Final Softcopy

To execute:

1. create a folder mybean

2. create a file bean.mft

3. create a file draw.java

4. compile draw.java (i.e.) E:\mybean>javac draw.java

2 fils will be created draw.class & draw$.class

5. then, create a jar file

E:\mybean>jar -cfm draw.jar bean.mft *.class

6. copy the create jar file draw.jar into the folder C:\bdk1_1\beans\jars

7. then, goto C:\bdk1_1\beans\beanbox & double click run.bat

8. the jar file draw will be loaded in the bean tool box

IT1403: Software Components Lab

Page 45: Cbt Lab Final Softcopy

Output:

IT1403: Software Components Lab

Page 46: Cbt Lab Final Softcopy

9.1)ACTIVEX-DLL

prjCrCheck -> Project NameclsCrCheck -> Classnamectype –Textbox1ram - Textbox2

Activex DLL

Client

Dim objCrCheck As clsCrCheckPrivate Sub Command1_Click()Dim ccValid As BooleanSet objCrCheck = New clsCrCheckMsgBox ctype.Text & ram.TextccValid = objCrCheck.fnValidateCreditCard(ctype.Text, ram.Text)If ccValid Then MsgBox "Valid Credit Card"Else MsgBox "Invalid Credit Card"End IfEnd Sub

ServerprjCrCheck -> Project NameclsCrCheck -> Classname Public Function fnValidateCreditCard(strCCType As String, strCCNumber As String) As BooleanDim bValid As Boolean strCCType = Trim(strCCType) Select Case UCase(strCCType) Case "VISA" strCCType = "V" Case "MASTER" strCCType = "M" Case "AMERICAN" strCCType = "A" End Select MsgBox "Hello Prefix->" & strCCType If fnPrefixCheck(strCCNumber, strCCType) And fnLenghtCheck(strCCNumber, strCCType) Then bValid = True Else bValid = False End If fnValidateCreditCard = bValid End Function

IT1403: Software Components Lab

Page 47: Cbt Lab Final Softcopy

Public Function fnPrefixCheck(strCCNumber As String, strCCType As String) As Boolean Dim validPrefix As Boolean Select Case UCase(strCCType) Case "V" If InStr(1, strCCNumber, "4") = 1 Then validPrefix = True End If Case "M" If InStr(1, strCCNumber, "51") = 1 Or InStr(1, strCCNumber, "52") = 1 Or InStr(1, strCCNumber, "53") = 1 Or InStr(1, strCCNumber, "54") = 1 Then validPrefix = True End If Case "A" If InStr(1, strCCNumber, "34") = 1 Or InStr(1, strCCNumber, "37") = 1 Then validPrefix = True End If End Select MsgBox "->" & strCCType & validPrefix fnPrefixCheck = validPrefixEnd Function

Public Function fnLenghtCheck(strCCNumber As String, strCCType As String) As Boolean

Dim validLength As Boolean Select Case UCase(strCCType) Case "V" If Len(strCCNumber) = 13 Or Len(strCCNumber) = 16 Then validLength = True End If Case "M" If Len(strCCNumber) = 16 Then validLength = True End If Case "A" If Len(strCCNumber) = 15 Then validLength = True End If End Select MsgBox "->" & Len(strCCNumber) & validLength fnLenghtCheck = validLength End Function

IT1403: Software Components Lab

Page 48: Cbt Lab Final Softcopy

OUTPUT:

IT1403: Software Components Lab

Page 49: Cbt Lab Final Softcopy

9.2)ACTIVEX- DOCUMENT

FORM 1

Private Sub Command1_Click()UserDocument.Hyperlink.NavigateTo "C:\Program Files\Microsoft Visual Studio\VB98\docForm1.vbd"End Sub

USER DOCUMENT :

Private Sub Command1_Click()MsgBox "hai"End Sub

Private Sub UserDocument_Initialize()Call form_loadEnd Sub

Public Sub form_load()End Sub

IT1403: Software Components Lab

Page 50: Cbt Lab Final Softcopy

OUTPUT:

IT1403: Software Components Lab