mwt record 2011-2012

Upload: balachandar-ramamurthy

Post on 05-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 MWT Record 2011-2012

    1/73

    AIM:

    To develop an RMI application that allows a client to transfer or download any

    types of files from a remote machine.

    ALGORITHM:

    Step 1: Start the program.

    Step 2: In the Client, x

    get the user input for directory, file name.

    Step 3: Create a new file in the directory with the specified file name.

    Step 4: Create an object for the remote interface downserver.

    Step 5: Use lookup() to search for JNDI name and download the file contents.

    Step 6: The client invokes methods in Remote interface to download the file.

    Step 7: Compile all the files by using set path= C:\Program

    Files\Java\jdk1.6.0_02\bin

    Step 8: Start RMI registry and compile the downimpl program.

    Step 9: Run the client and display the result.

    Step 10: Stop the program.

    SOURCE CODE

    /* downserver.java */

    import java.rmi.*;

    import java.io.*;

    public interface downserver extends Remote

    {

    String download(File f) throws RemoteException;

    }

    /* dclient.java */

    import java.rmi.*;

    import java.io.*;

    public class dclient

    {

    public static void main(String args[])

    - 1 -

    Ex No: 1

    Date: 01/07/11REMOTE METHOD INVOCATION

  • 7/31/2019 MWT Record 2011-2012

    2/73

    {

    try

    {

    String file,dir;

    BufferedReader din=new BufferedReader(new InputStreamReader

    (System.in));

    System.out.println("Enter directory name:");

    dir=din.readLine();

    System.out.println("Enter the file name:");

    file=din.readLine();

    File ff=new File(dir,file);

    downserver dr=(downserver)Naming.lookup("rmi://localhost/downimpl");

    String s=dr.download(ff);

    System.out.println(s);

    }

    catch(Exception e)

    { } } }

    /* downimpl.java */

    import java.rmi.*;

    import java.io.*;

    import java.rmi.server.*;

    public class downimpl extends UnicastRemoteObject implements downserver

    {

    public downimpl() throws RemoteException

    {

    }

    public String download(File f)

    {

    String str=" ";

    try

    {

    FileInputStream in=new FileInputStream(f);

    int l=in.available();

    - 2 -

  • 7/31/2019 MWT Record 2011-2012

    3/73

    for(int i=1;i

  • 7/31/2019 MWT Record 2011-2012

    4/73

    Next we will run the server program (downimpl.java) in following manner

    Now we will open another command prompt and run the client program

    (dclient.java) in following manner. We will get the output.

    RESULT

    Thus the above application Remote Method Invocation has been executedsuccessfully.

    - 4 -

  • 7/31/2019 MWT Record 2011-2012

    5/73

    AIM:

    To implement the Java Bean to draw graphical objects and to display it in

    Frame.

    ALGORITHM

    Step 1: Start->All Programs->Net BeansIDE Choose File->New Project in dialog Box.

    Choose category as General and select Project as Java Application.

    Step2 : Give Project name: JavaBean & deselect Create Main class and set as Main

    project. Click finish to create the class.

    - 5 -

    Ex No:2

    Date: 08/07/11CREATING JAVA BEAN

  • 7/31/2019 MWT Record 2011-2012

    6/73

    Now we will get the following window.

    Right Click Java Bean->New->Java Class and give class name as JavaBean

    Step 3: In left pane Double click on JavaBean.java. Now in right side pane type the

    corresponding code.

    Step 4: Now we compile the JavaBean.java code in following manner. In left side

    panner Right click the JavaBean.java -> Compile File

    - 6 -

  • 7/31/2019 MWT Record 2011-2012

    7/73

    Step 5: Next we will select Files Tab in Left Side Pane and double click the build.xml

    file from JavaBean Folder. Now we add our own xml - code after the comment with in

    the tag.

    Step 6: Now we compile the above build.xml code in the following manner. Right

    Click build.xml -> Run Target -> Other Targets -> build Please following the below

    screen.

    Step 7:Next we double click the JavaBean.jar file from left pane in Files Tab, we got

    MANIFEST.MF file.

    Now we will open the MANIFEST.MF (Double click) file and check the

    following information is correct or not.

    Name: JavaBean.class

    Java-Bean: true

    Step 8: Next we will create one Java Frame class in the following manner Select

    Projects Tab ->JavaBean Right Click -> New JFrame Form. Now we give the class

    name as BeanLoader and click finish.

    - 7 -

  • 7/31/2019 MWT Record 2011-2012

    8/73

    Step 9: In palette Explorer (it available from Right side) Right click the Palette

    Explorer - >Choose Palette Manager. Now we will get the following Dialog box.

    Step 10: In palette Manager Dialog box Please click the Add from JAR Button Now

    we will get the following Dialog box

    Please select the appropriate JavaBean.jar file from your corresponding Project

    Folder then click -> next Now choose the available components to add to the palette

    then click->next

    Now choose the palette category where to add the components. Here Beans

    has been selected. Then click finish.

    - 8 -

  • 7/31/2019 MWT Record 2011-2012

    9/73

    Now the Palette Manager Dialog box will appear with selection of Beans

    Component then ->close.

    Now go to Palette Explorer and Click the Beans Division check whether the

    corresponding JavaBean has been added or not.

    Now Drop the JavaBean Component from Beans Division and drag into the

    BeanLoader.java Frame window.

    Next we will run the BeanLoader.java. Right click BeanLoader.java -> click

    Run File. Now we got the following output

    SOURCE CODE

    File Name: JavaBean.java

    import java.awt.Color;

    import java.beans.XMLDecoder;

    import javax.swing.JLabel;

    import java.io.Serializable;

    public class JavaBean extends JLabel implements Serializable {

    public JavaBean() {

    setText( "MiddleWare" );

    setOpaque( true );

    setBackground( Color.RED );

    setForeground( Color.YELLOW );

    setVerticalAlignment( CENTER );

    - 9 -

  • 7/31/2019 MWT Record 2011-2012

    10/73

    setHorizontalAlignment( CENTER );

    } }

    XML coding:

    SCREEN OUTPUT

    RESULT:

    Thus the above application Java Beans has been executed successfully.

    - 10 -

  • 7/31/2019 MWT Record 2011-2012

    11/73

    AIM:

    To develop a simple calculator in EJB Application to perform a basic

    mathematical operations.

    PROCEDURE / ALGORITHM

    Step1:

    Start All ProgramsNetBeansFile Menu Select New Project Choose Java

    (Categories) and Enterprise Application (Projects)and click next.

    Step : 2

    In Name and Location Menu give the Project name and Click Next. Set the

    Server as Glass Fish, Select the Java Version, Check the Selection of EJB Module

    and Web Application Module and click finish.

    - 11 -

    Ex No: 3

    Date: 15/07/11CREATING A SIMPLE CALCULATOR USING EJB

  • 7/31/2019 MWT Record 2011-2012

    12/73

    Step 3:

    Ensure the name of the Project (Calculator), EJB Module(Calculator-ejb) and

    Web Application module (Calculator-war) was created.

    Right Click EJB Module Select Session Bean Give EJB Name Give

    Package Name Select the Session type as Stateless Check the interface as

    Remote click Finish.

    - 12 -

  • 7/31/2019 MWT Record 2011-2012

    13/73

    Step 4:

    Ensure the Creation of a Bean (CalculatorBean) and Remote interface

    (CalculatorBeanRemote) file

    Type the coding for the Remote interface java file

    Type the coding in the Java Bean file

    Step 5:

    Select The Web Application module (War File), Right click on WebPages

    Select jsp/ html Create the Client form (form.jsp) type the following code in form.jsp

    Type the Coding for form.jsp

    Step 6:

    Now Create a Servlet file to handle the client request. The Request method was

    either GET/POST.

    Right click on the source package of Calculator-war and select Servlet and

    name it as WebServlet and click finish

    - 13 -

  • 7/31/2019 MWT Record 2011-2012

    14/73

    Step7:.

    Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet

    file (WebServlet.java) Select Insert code Select Call Enterprise Bean Select

    the Enterprise Bean (CalculatorBean) click Ok. Ensure the import statement coding

    has the import calculator.CalculatorRemote; and in the Coding line

    @EJB

    private CalculatorRemote calculatorBean;

    Type the coding for WebServlet.java

    - 14 -

  • 7/31/2019 MWT Record 2011-2012

    15/73

    Step 8:

    Build, Deploy and Run the Project

    Right click the Project Select Clean & Build

    Right Click the Project

    Select DeployRight Click the Project Run

    Clean & Build

    Deploy & Run

    Step 9:

    Observe the output in Web Browser

    - 15 -

  • 7/31/2019 MWT Record 2011-2012

    16/73

    SOURCE CODE

    CalculatorBeanRemote.java

    package calculator;

    import javax.ejb.Remote;

    import java.math.*;

    import java.lang.annotation.*;

    @Remote

    public interface CalculatorRemote

    {

    public float add(float x,float y);

    public float subtract(float x,float y);

    public float multiply(float x,float y);

    public float division(float x,float y);

    }

    CalculatorBean.java

    package calculator;

    import javax.ejb.Stateless;

    import java.math.*;import javax.ejb.Remote;

    @Stateless(name="CalculatorBean")

    @Remote(CalculatorRemote.class)

    public class CalculatorBean implements CalculatorRemote

    {

    public float add(float x,float y)

    { return x+y; }

    public float subtract(float x,float y)

    { return x-y; }

    public float multiply(float x,float y)

    { return x*y; }

    public float division(float x,float y)

    { return x/y; } }

    - 16 -

  • 7/31/2019 MWT Record 2011-2012

    17/73

    form.jsp

    Calculator

    Calculator

    Enter first value:

    Enter second value:

    Select your choice AdditionSubtraction

    MultiplicationDivision

    index.jsp

    JSP Page

    Welcome to EJB Stateless Session Bean

    Click to call the

    Bean

    WebServlet.java

    import java.io.*;

    import java.net.*;

    import javax.servlet.*;

    import javax.servlet.http.*;

    import javax.ejb.*;

    import calculator.CalculatorRemote;

    - 17 -

  • 7/31/2019 MWT Record 2011-2012

    18/73

    public class Webservlet extends HttpServlet {

    @EJB

    private CalculatorRemote calculatorBean;

    protected void doGet(HttpServletRequest request, HttpServletResponse

    response)throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out=response.getWriter();

    float result=0;

    System.out.println(result);

    try {

    String s1=request.getParameter("num1");

    String s2=request.getParameter("num2");

    String s3=request.getParameter("group1");

    if(s1!=null && s2!=null) {

    System.out.println(s3);

    Float num1=new Float(s1);

    Float num2=new Float(s2);

    if(s3.equals("add"))

    {

    result=calculatorBean.add(num1.floatValue(),num2.floatValue());

    out.println();

    out.println("The Result For The Choice

    ADDITION
    ");

    out.println("");

    out.println("The Number1 is:

    "+num1+"");

    out.println("The Number2 is:

    "+num2+"");

    out.println("The Result is:

    "+result+"");

    out.println("""); }

    else if(s3.equals("subtract")) {

    result=calculatorBean.subtract(num1.floatValue(),num2.floatValue());

    out.println("");

    - 18 -

  • 7/31/2019 MWT Record 2011-2012

    19/73

    out.println("The Result For The Choice

    SUBTRACT
    ");

    out.println("");

    out.println("The Number1 is:

    "+num1+"");

    out.println("The Number2 is:

    "+num2+"");

    out.println("The Result is:

    "+result+"");

    out.println(""); }

    else if(s3.equals("multiply")) {

    result=calculatorBean.multiply(num1.floatValue(), num2.floatValue());

    out.println("");

    out.println("The Result For The Choice MULTIPLICATION


    ");

    out.println("");

    out.println("The Number1 is:

    "+num1+"");

    out.println("The Number2 is:

    "+num2+"");

    out.println("The Result is:

    "+result+"");

    out.println(""); }

    else {

    result=calculatorBean.division(num1.floatValue(),num2.floatValue());

    out.println("");

    out.println("The Result For The Choice

    DIVISION
    ");

    out.println("");

    out.println("The Number1 is:

    "+num1+"");

    out.println("The Number2 is:

    "+num2+"");

    out.println("The Result is:

    - 19 -

  • 7/31/2019 MWT Record 2011-2012

    20/73

    "+result+"");

    out.println(""); } } }

    catch(Exception e)

    { e.printStackTrace(); } }

    SCREEN OUTPUT

    Screen shot 1:

    Screen shot 2:

    - 20 -

  • 7/31/2019 MWT Record 2011-2012

    21/73

    Screen Shot 3:

    RESULT

    Thus the above application Simple Calculator using EJB has been executed

    successfully.

    - 21 -

  • 7/31/2019 MWT Record 2011-2012

    22/73

    AIM:

    To develop a simple EJB Application to perform a Bank Transaction operations.

    PROCEDURE / ALGORITHM

    Step1:

    Start All ProgramsNetBeansFile Menu Select New Project

    Choose Java (Categories) and Enterprise Application (Projects) and click next.

    Step: 2

    In Name and Location Menu give the Project name and Click Next. Set the

    Server as Glass Fish, Select the Java Version, Check the Selection ofEJB Module and

    Web Application Module and click finish.

    - 22 -

    Ex No: 4

    Date: 22/07/11CREATING A SIMPLE BANK TRANSACTION USING

    EJB

  • 7/31/2019 MWT Record 2011-2012

    23/73

    Step 3:

    Ensure the name of the Project (BankApplication), EJB Module

    (BankApplication-ejb) and Web Application module (BankApplication-war) was

    created.

    Right Click EJB Module Select Session Bean Give EJB Name Give

    Package Name Select the Session type as Stateful Check the interface as

    Remote click Finish.

    - 23 -

  • 7/31/2019 MWT Record 2011-2012

    24/73

    Step4:

    Ensure the Creation of a Bean (BankApplication.java) and Remote interface

    (BankApplicationRemote.java) file

    Type the coding for the Remote interface java file

    Type the coding in the Java Bean file

    Step5:

    Select The Web Application module (War File), Right click on WebPages

    Select jsp/ html Create the Client form (BankForm.jsp) type the following code in

    BankForm.jsp

    - 24 -

  • 7/31/2019 MWT Record 2011-2012

    25/73

    Type the Coding for BankForm.jsp

    Step 6

    Now Create a Servlet file to handle the client request. The Request method was

    either GET/POST.

    Right click on the source package ofBankApplication-war and select Servlet

    and name it as BankServlet and click finish

    - 25 -

  • 7/31/2019 MWT Record 2011-2012

    26/73

    Step7:.

    Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet

    file (BankServlet.java) Select Insert code Select Call Enterprise Bean Select

    the Enterprise Bean (BankApplication) click Ok. Ensure the import statement coding

    has the import BankApplication.BankApplicationRemote; and in the Coding line

    BankApplicationRemote bankApplication = lookupBankApplicationRemote();

    Type the coding for BankServlet.java

    Step 8:

    - 26 -

  • 7/31/2019 MWT Record 2011-2012

    27/73

    Build, Deploy and Run the Project

    Right click the Project Select Clean & Build

    Right Click the Project Select Deploy

    Right Click the Project Run

    Clean & Build

    Deploy & Run

    Step 9:

    Observe the output in Web Browser

    - 27 -

  • 7/31/2019 MWT Record 2011-2012

    28/73

  • 7/31/2019 MWT Record 2011-2012

    29/73

    Enter the amount in rupees:

    Select your choice:Deposit

    Withdraw

    index.jsp

    JSP Page

    Welcome to EJB Stateful Session Bean

    Click to call the Bean

    BankServlet.java

    import BankApplication.BankApplicationRemote;

    import java.io.IOException;

    import java.io.PrintWriter;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import javax.naming.Context;

    import javax.naming.InitialContext;

    import javax.naming.NamingException;

    import javax.servlet.ServletException;

    import javax.servlet.annotation.WebServlet;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    public class BankServlet extends HttpServlet {

    BankApplicationRemote bankApplication = lookupBankApplicationRemote();

    protected void doGet(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    // processRequest(request, response);

    - 29 -

  • 7/31/2019 MWT Record 2011-2012

    30/73

    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out=response.getWriter();

    float result=0;

    try {

    String s1=request.getParameter("amt");

    String s2=request.getParameter("group1");

    if(s1!=null && s2!=null) {

    Float amt=new Float(s1);

    if(s2.equals("dep")) {

    result=bankApplication.deposit(amt.floatValue());

    out.println("");

    out.println("

    Bank Transaction Form

    ");

    out.println("");

    out.println(" Rs."+amt+" /-was Deposited in your

    Account");

    out.println(" current balance isRs."+result+"/-

    ");

    out.println("Back To Transaction

    Form");

    out.println(""); }

    else if(s2.equals("with")) {

    result=bankApplication.withdraw(amt.floatValue());

    out.println("");

    out.println("

    Bank Transaction Form

    ");

    out.println("");

    out.println(" Rs."+amt+" /-was With Drawn From

    your Account");

    out.println(" current balance isRs."+result+"/-

    ");

    out.println("Back To Transaction

    Form");

    out.println(""); } } }

    - 30 -

  • 7/31/2019 MWT Record 2011-2012

    31/73

    catch(Exception e)

    { e.printStackTrace(); } }

    SCREEN OUTPUT

    Screen shot 1:

    Screen shot 2:

    - 31 -

  • 7/31/2019 MWT Record 2011-2012

    32/73

    Screen Shot 3:

    Screen Shot 4:

    RESULT

    The above application Simple Bank Transaction using EJB has been executed

    successfully.

    - 32 -

  • 7/31/2019 MWT Record 2011-2012

    33/73

    AIM:

    To develop a simple EJB Application to perform Library Management

    operations.

    PROCEDURE / ALGORITHM

    Step1:

    Start All ProgramsNetBeansFile Menu Select New Project

    Choose Java (Categories) and Enterprise Application (Projects) and click next.

    Step 2

    In Name and Location Menu give the Project name and Click Next. Set the

    Server as Glass Fish, Select the Java Version, Check the Selection ofEJB Module and

    Web Application Module and click finish.

    - 33 -

    Ex No: 5

    Date: 29/07/11CREATING A SIMPLE LIBRARY MANAGEMENT

    USING EJB

  • 7/31/2019 MWT Record 2011-2012

    34/73

    Step 3:

    Ensure the name of the Project (LIB), EJB Module (LIB-ejb) and Web

    Application module (LIB-war) was created.

    Right Click EJB Module Select Session Bean Give EJB Name Give

    Package Name Select the Session type as Stateful Check the interface as

    Remote click Finish.

    - 34 -

  • 7/31/2019 MWT Record 2011-2012

    35/73

    Step4:

    Ensure the Creation of a Bean (LIBBean.java) and Remote interface

    (LIBBeanRemote.java) file

    Type the coding for the Remote interface java file

    Type the coding in the Java Bean file

    Step5:

    Select The Web Application module (War File), Right click on WebPages

    Select jsp/ html Create the Client form (LIBForm.jsp) type the following code in

    LIBForm.jsp

    Type the Coding for LIBForm.jsp

    Step6:

    Now Create a Servlet file to handle the client request. The Request method was

    either GET/POST.

    Right click on the source package ofLIB-war and select Servlet and name it as

    LIBServ.java and click finish

    - 35 -

  • 7/31/2019 MWT Record 2011-2012

    36/73

    Step7:

    Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet

    file (LIBServ.java) Select Insert code Select Call Enterprise Bean Select the

    Enterprise Bean (LIBBean) click Ok. Ensure the import statement coding has the

    import LIB.LIBBeanRemote; and in the Coding line

    LIBBeanRemote lIBBean = lookupLIBBeanRemote();

    Type the coding for LIBServ.java

    - 36 -

  • 7/31/2019 MWT Record 2011-2012

    37/73

    Step 8:

    Build, Deploy and Run the Project

    Right click the Project Select Clean & Build

    Right Click the Project Select Deploy

    Right Click the Project Run

    Clean & Build

    Deploy

    - 37 -

  • 7/31/2019 MWT Record 2011-2012

    38/73

    Step 9:

    Observe the output in Web Browser

    SOURCE CODELIBBeanRemote.java

    package LIB;

    import javax.ejb.Remote;

    import java.rmi.RemoteException;

    @Remote

    public interface LIBBeanRemote {

    public String Issue(String acno,String bname)throws RemoteException;

    public String Return(String acno)throws RemoteException; }

    LIBBean.java

    package LIB;

    import javax.ejb.Stateful;

    @Stateful

    public class LIBBean implements LIBBeanRemote {

    private static int count=0;

    private String c_no[]=new String[100];

    - 38 -

  • 7/31/2019 MWT Record 2011-2012

    39/73

    private String ac_no[]=new String[100];

    @Override

    public String Issue(String acno,String bname) {

    ac_no[count]=acno;

    c_no[count]=bname;

    count++;

    return "Successfully Issued"; }

    @Override

    public String Return(String acno) {

    for(int i=0;i

  • 7/31/2019 MWT Record 2011-2012

    40/73

    LIBServ.java

    import LIB.LIBBeanRemote;

    import java.io.IOException;

    import java.io.PrintWriter;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import javax.naming.Context;

    import javax.naming.InitialContext;

    import javax.naming.NamingException;

    import javax.servlet.ServletException;

    import javax.servlet.annotation.WebServlet;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    public class LIBServ extends HttpServlet {

    LIBBeanRemote lIBBean = lookupLIBBeanRemote();

    @Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    // processRequest(request, response);

    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    String result="";

    try {

    String s1=request.getParameter("acno");

    String s2=request.getParameter("bname");

    String s3=request.getParameter("group1");

    if(s1!=null && s2!=null) {

    if(s3.equals("iss")) {

    result=lIBBean.Issue(s1,s2);

    out.println("Welcome");

    - 40 -

  • 7/31/2019 MWT Record 2011-2012

    41/73

    out.println("The Book Bearing Account No" + s1 + "and title" + s2 + "was" +

    result + ""); }

    else if(s3.equals("with"))

    {

    result=lIBBean.Return(s1);

    out.println("The Book Bearing Account No" + s1 + "was" + result + "");

    } }

    out.println("Go Home Page"); }

    catch(Exception e){} }

    - 41 -

  • 7/31/2019 MWT Record 2011-2012

    42/73

    SCREEN OUTPUT

    Screen shot 1:

    Screen shot 2:

    Screen Shot 3

    RESULT

    Thus the above application Library Management System using EJB has been

    executed successfully.

    - 42 -

  • 7/31/2019 MWT Record 2011-2012

    43/73

    AIM:

    To write a program to create an Active-X control in C#.NET

    ALGORITHM:

    Step 1: Start the process

    Step 2: Click start->All programs->Microsoft Visual Studio 2005-> Microsoft

    Visual Studio 2005->File->New Project->Project Types as Visual C# and

    Templates as Windows Application

    Step 3: Design the form with the following controls in the form

    RichTextBox

    Save Command Button

    Open Command Button

    Color Command Button

    SaveFileDialog Control

    OpenFileDialog control

    ColorDialog Control

    Step 4: Write event handling procedures for Save, Open and Color commands

    Step5: Execute the program

    Step 6: Stop the program

    FORM DESIGN

    - 43 -

    Ex No: 6

    Date: 05/08/11ACTIVEX CONTROL

  • 7/31/2019 MWT Record 2011-2012

    44/73

    SOURCE CODE

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    namespace ActControl {

    public partial class Form1 : Form {

    public Form1()

    { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)

    {

    richTextBox1.Enabled = true;

    richTextBox1.Text = "";

    richTextBox1.Focus();

    }

    private void button2_Click(object sender, EventArgs e)

    {

    if (openFileDialog1.ShowDialog() != DialogResult.Cancel)

    {

    - 44 -

  • 7/31/2019 MWT Record 2011-2012

    45/73

    richTextBox1.LoadFile(openFileDialog1.FileName,

    RichTextBoxStreamType.PlainText); } }

    private void button3_Click(object sender, EventArgs e)

    {

    if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)

    {

    richTextBox1.SaveFile(saveFileDialog1.FileName,

    RichTextBoxStreamType.PlainText); } }

    private void button4_Click(object sender, EventArgs e)

    {

    if (colorDialog1.ShowDialog() != DialogResult.Cancel)

    {

    richTextBox1.SelectionColor = colorDialog1.Color; } }

    private void button5_Click(object sender, EventArgs e)

    {

    if (fontDialog1.ShowDialog() != DialogResult.Cancel)

    {

    richTextBox1.SelectionFont = fontDialog1.Font; } }

    private void Form1_Load(object sender, EventArgs e)

    {

    richTextBox1.Enabled = false; }

    private void button6_Click(object sender, EventArgs e) {

    this.Close(); } } }

    SCREEN OUTPUT:

    Screen shot of SaveFileDialog control to save the Content of Rich text Box to a file

    - 45 -

  • 7/31/2019 MWT Record 2011-2012

    46/73

    Screen shot of OpenFileDialog control to open the file

    - 46 -

  • 7/31/2019 MWT Record 2011-2012

    47/73

    Screen shot of FontDialogBox to apply the font settings

    RESULT

    Thus the above application Active-x control has been executed successfully.

    - 47 -

  • 7/31/2019 MWT Record 2011-2012

    48/73

    AIM

    To Develop a Component for Currency Conversion using .NET

    ALGORITHM

    Step 1: Start the program.

    Step 2: Goto Start -> All Programs -> MicrosoftVisualStudio 2005.

    Step 3: In the start page select File -> NewProject.

    Step 4: Select the desired language and Select the template as WindowsApplication.

    Give the FileName and Location.

    Step 5: In the Design view create the Form with the fileds for

    Entering the amount,

    Displaying the rupees equivalent,

    Three Buttons: Calculate, Clear, Exit,

    Four RadioButtons: US Doller, Pound, Euro, Dinar.

    Step 6: Run the program using F5.

    Step 7: Stop the Program.

    FORM DESIGN

    - 48 -

    Ex No: 7

    Date: 12/08/11CURRENCY CONVERSION

  • 7/31/2019 MWT Record 2011-2012

    49/73

    SOURCE CODE

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    namespace CurrencyConversion

    { public partial class Form1 : Form

    { public Form1()

    { InitializeComponent(); }

    // CODE CORRESPONDING TO CALCULATE BUTTON

    private void button1_Click(object sender, EventArgs e)

    {

    Double tot = 0;

    Double a = Double.Parse(textBox1.Text);

    if (radioButton1.Checked == true)

    tot = a * 45.05;

    else if (radioButton2.Checked == true)

    tot = a * 71.31;

    else if (radioButton3.Checked == true)

    tot = a * 60.66;

    else

    tot = a * 119.47;

    textBox2.Text = tot.ToString("0.000"); }

    // CODE CORRESPONDING TO CLEARBUTTON

    private void button2_Click(object sender, EventArgs e)

    {

    textBox1.Text = " ";

    textBox2.Text = " ";

    radioButton1.Checked = true;

    textBox1.Focus(); }

    - 49 -

  • 7/31/2019 MWT Record 2011-2012

    50/73

    // CODE CORRESPONDING TO EXIT BUTTON

    private void button3_Click(object sender, EventArgs e)

    { Application.Exit(); } } }

    SCREEN OUTPUT

    RESULT

    - 50 -

  • 7/31/2019 MWT Record 2011-2012

    51/73

    Thus the above application Currency Conversion using .NET was executed

    successfully.

    - 51 -

  • 7/31/2019 MWT Record 2011-2012

    52/73

    AIM:

    To develop a component for encryption and Decryption using COM / .NET

    ALGORITHM:

    Step 1: Goto Start->All Programs->Microsoft Visual Studio.

    Step 2: In the start page File->New Project select the desired language and select the

    template as Windows Application by selecting Visual C#, Give the filename and

    location.

    Step 3: In design Place the label, textbox, buttons for appropriate operations.

    Step 4: In Button click event,For Encrypt convert the given string to integer(ASCII

    values),add 100 with each character and then add the specified length as first letter.

    Step 5: For Decrypt get the string, take first char as splitting length, using this find the

    no of character and then subtract with 100 for find the original string.

    FORM DESIGN:

    - 52 -

    Ex No: 8

    Date: 27/08/11ENCRYPTION AND DECRYPTION

  • 7/31/2019 MWT Record 2011-2012

    53/73

    SOURCE CODE:

    using System; //Import the necessary library files

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    namespace encryption //Name space encryption provides working environment

    {

    public partial class Form1 : Form //Define the class which inherits the Form class

    {

    string res,receiver;

    string a;

    int[] t = new int[100];

    public Form1() //Constructor for the class Form1

    {

    InitializeComponent(); //Initialize all the components

    }

    private void button1_Click(object sender, EventArgs e)

    {

    //Code for Encrypting

    if (button1.Text == "Encrypt")

    {

    label1.Text = "Encrypted Text"; //change the label text and button text

    button1.Text = "Decrpt";

    a = textBox1.Text;

    for (int j = 0; j < 100; j++) //separate the letters to int

    t[j] = 0;

    res = "";

    for (int i = 0; i < a.Length; i++) //Convert to ASCII value and add 100

    {

    t[i] = Convert.ToInt32(a[i]);

    t[i] = t[i] + 100; //add 100 with separated Integer

    - 53 -

  • 7/31/2019 MWT Record 2011-2012

    54/73

    res = res + Convert.ToString(t[i]);

    }

    textBox1.Text = "3"+res; //Specify the spliting length

    receiver = "3"+res;

    } else {

    label1.Text = "The Result is";

    button1.Text = "Encrypt";

    textBox1.Text = ""; //Find the legth and size

    char size = receiver[0],solution;

    string x = Convert.ToString(size);

    int orgsize = Convert.ToInt32(x);

    int num = 0, org, l = 1;

    int size1 = receiver.Length, length = size1 / orgsize, o = orgsize + 1;

    //To convert the original string

    for (int i = 0; i < length; i++)

    {

    string textt = "";

    for (int j =l; j < o ; j++)

    {

    textt = textt + Convert.ToChar(receiver[j]); //separate the text and convert to

    original letter

    }

    num = Convert.ToInt32(textt); //Read the numbers

    org = num - 100;

    solution = Convert.ToChar(org); //concatenate the string

    textBox1.Text = textBox1.Text + Convert.ToString(solution);

    o += orgsize;

    l += orgsize; } } } } }

    - 54 -

  • 7/31/2019 MWT Record 2011-2012

    55/73

    SCREEN OUTPUT

    Screen Shot1

    Screen Shot 2

    - 55 -

  • 7/31/2019 MWT Record 2011-2012

    56/73

  • 7/31/2019 MWT Record 2011-2012

    57/73

    AIM:

    To develop a component to retrieving the information from Message Box using

    COM / .NET

    ALGORITHM

    Step 1: Start the process.

    Step 2: Place the controls in form look like given below.

    Step 3: Double click on the command button Information and enter the following codes.

    private void button1_Click(object sender, EventArgs e)

    {

    MessageBox.Show("Hi! friends", "Information", MessageBoxButtons.OK,

    MessageBoxIcon.Information); }

    Step 5: Double click on the command button Question and enter the following codes.

    private void button4_Click(object sender, EventArgs e)

    {

    dr = MessageBox.Show("Do you wanna continue?", "Question",

    MessageBoxButtons.YesNo, MessageBoxIcon.Question);

    if (dr == DialogResult.Yes)

    MessageBox.Show("Yes! you can continue your work", "Yes",

    MessageBoxButtons.OK, MessageBoxIcon.Information);

    else

    MessageBox.Show("Thanks for being with us", "No", MessageBoxButtons.OK,

    MessageBoxIcon.Information); }Step 6: Double click on the command button Exclamination and enter the following

    - 57 -

    Ex No:9

    Date: 15/09/11RETERVING INFORMATION FROM MESSAGE BOX

  • 7/31/2019 MWT Record 2011-2012

    58/73

    Codes.

    private void button2_Click(object sender, EventArgs e)

    {

    MessageBox.Show("Wow! wat a nice picture", "Exclamation",

    MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }

    Step 7: Double click on the command button Warning and enter the following codes.

    private void button5_Click(object sender, EventArgs e)

    {

    dr = MessageBox.Show("Your system is infected by Virus!", "Warning",

    MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);

    if (dr == DialogResult.Retry)

    MessageBox.Show("You lose unsaved document", "Abort", MessageBoxButtons.OK,

    MessageBoxIcon.Information);

    else if (dr == DialogResult.Abort)

    MessageBox.Show("Oops! your system is attacked severly!", "Abort",

    MessageBoxButtons.OK, MessageBoxIcon.Information);

    else

    MessageBox.Show("Your System is stillaffected!","Ignore",MessageBoxButtons.OK,MessageBoxIcon.Information); }

    Step 8: Double click on the command button Error and enter the following codes.

    private void button3_Click(object sender, EventArgs e)

    {

    MessageBox.Show("Error in the Program", "Error", MessageBoxButtons.OK,

    MessageBoxIcon.Error); }

    Step 9: Double click on the command button Stop and enter the following codes.

    private void button6_Click(object sender, EventArgs e)

    {

    dr = MessageBox.Show("Save and close all the documents", "Stop",

    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop);

    if (dr == DialogResult.Yes)

    MessageBox.Show("Document is saved successfully", "Yes", MessageBoxButtons.OK,

    MessageBoxIcon.Information);

    - 58 -

  • 7/31/2019 MWT Record 2011-2012

    59/73

  • 7/31/2019 MWT Record 2011-2012

    60/73

    Screen shot-3

    RESULT

    Thus the above application Retrieving information from message Box has

    been executed successfully.

    - 60 -

    Ex No: 10

    Date: 23/09/11STOCK MARKET EXCHANGE INFORMATION

  • 7/31/2019 MWT Record 2011-2012

    61/73

    AIM:

    Develop a middleware component for retrieving Stock Market Exchange

    information using CORBA.

    ALGORITHM:

    STEP 1: Start the process.

    STEP 2: Create the IDL file and save it as stock.idl

    i) Declare the CORBA IDL module.

    ii) Declare the interface

    iii) Declare the operations and

    iv) Mapping the IDL to java

    STEP 3: Create the server method and save it as StockServer.java

    STEP 4: Create the client method and save it as StockClient..java

    STEP 5: Compile the StockServer and StockClient as

    javac StockServer.java StockApp/*.java

    javac StockClient.java StockApp/*.java

    STEP 6: Execute the Stock market Application as following below.

    i) Start orbdstart orbd ORBInitialPort 1050 ORBInitialHost localhost

    ii) Run the StockServer by using

    start java StockServer ORBInitialPort 1050 ORBInitialHost

    localhost

    iii) Run the StockClient by using

    start java StockClient ORBInitialPort 1050 ORBInitialHost

    localhost

    STEP 7: Stop the process.

    - 61 -

  • 7/31/2019 MWT Record 2011-2012

    62/73

  • 7/31/2019 MWT Record 2011-2012

    63/73

    w.setORB(orb);

    //get object reference from the servant

    org.omg.CORBA.Object ref=rootpoa.servant_to_reference(w);

    Stock href=StockHelper.narrow(ref);

    //get the root naming context

    org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService");

    NamingContextExt ncRef=NamingContextExtHelper.narrow(objRef);

    //bind the object reference in naming

    String name="p1";

    NameComponent path[]=ncRef.to_name(name);

    ncRef.rebind(path,href);

    System.out.println("Server Ready and Waiting ");

    //Wait for invocations from clients.

    orb.run(); }

    catch(Exception e)

    {

    System.out.println("Error occur"+e);

    e.printStackTrace(System.out); } } }

    //Client program named as StockClient.java

    import StockApp.*;

    import org.omg.CosNaming.*;

    import org.omg.CosNaming.NamingContextPackage.*;

    import org.omg.CORBA.*;

    import java.io.*;

    public class StockClient {

    static Stock k;

    public static void main(String arg[]) {

    String[ ] uid={"M120","p1190","M890","K345"};

    String[ ] p={"Hutch","Infosys","Wipro","Cognizant"};

    double[ ] unit={5,6,5,6};

    double[ ] noshares={10,4,7,3};

    double[ ] total={0,0,0,0};

    int ch;

    - 63 -

  • 7/31/2019 MWT Record 2011-2012

    64/73

    try {

    //create and initialize the ORB

    ORB orb=ORB.init(arg,null);

    //get the root naming context

    org.omg.CORBA.Object

    objRef=orb.resolve_initial_references("NameService");

    //use NamingContextExt instead of NamingContext.This is the part of the

    interoperable naming service.

    NamingContextExt ncRef=NamingContextExtHelper.narrow(objRef);

    //resolve the object reference in naming

    String name="p1";

    k=StockHelper.narrow(ncRef.resolve_str(name));

    for(int i=0;i

  • 7/31/2019 MWT Record 2011-2012

    65/73

    System.out.println("Enter your BuyerId:");

    String bid=k1.readLine();

    System.out.println("Enter company Name");

    String co=k1.readLine();

    System.out.println("No.of share you want to buy:");

    double sh=Double.parseDouble(k1.readLine());

    System.out.println("Enter Seller id:");

    String sid=k1.readLine();

    for(int i=0;i

  • 7/31/2019 MWT Record 2011-2012

    66/73

    if(uid[i].equals(bid1)) {

    if(p[i].equals(co1)) {

    noshares[i]-=sh1;

    total[i]=unit[i]*noshares[i]; } } }

    break;

    case 3:

    System.out.println("\t\tSTATUS OF NSE");

    System.out.println("\t--------------------------------------------------------");

    System.out.println("\tUid\tCompanyName\tUnit\tNoofShares\tTotal");

    System.out.println("\t--------------------------------------------------------");

    for(int i=0;i

  • 7/31/2019 MWT Record 2011-2012

    67/73

    Menu Options

    1. Buy

    2. Sell

    3. Display

    Enter your choice: 1

    Enter your Buyer Id: M124

    Enter Company Name: Hutch

    No. of share you want to Buy: 5

    Enter Seller Id: 123

    Do you want to continue(y/n): y

    Menu Options

    1. Buy

    2. Sell

    3. Display

    Enter your choice: 3

    STATUS OF NSE

    -----------------------------------------------------------------------------

    Uid Company Name Unit No of shares total

    -----------------------------------------------------------------------------

    M124 Hutch 5.0 15.0 75.0

    P1190 Infosys 6.0 4.0 24.0

    M890 Hutch 5.0 7.0 35.0

    K345 Infosys 6.0 3.0 18.0

    Do you want to continue(y/n): n

    RESULT

    Thus the above application Stock Exchange Information using CORBA has

    been executed successfully.

    - 67 -

  • 7/31/2019 MWT Record 2011-2012

    68/73

  • 7/31/2019 MWT Record 2011-2012

    69/73

    SOURCE CODE:

    //IDL INTERFACE

    module WeatherApp {

    interface Weather {

    void adjusttemp(in double r);

    double getcurrent();

    double getMax();

    double getMin();

    void call(in double k);

    oneway void shutdown(); }; };

    //CLIENT PROGRAM

    import WeatherApp.*;

    import org.omg.CosNaming.*;

    import org.omg.CosNaming.NamingContextPackage.*;

    import org.omg.CORBA.*;

    public class WeatherClient {

    static Weather wt;

    public static void main(String args[]) {

    double[][] wr={{-1.5,2.5,4.2,-4.5},{-2.3,-7.8,6.2,-4.7},{4.3,-3.6,5.9,-1.7}};

    String[] wc={"Chennai","Mumbai","Delhi","Calcutta"};

    int i,j;

    try {

    ORB w=ORB.init(args,null);

    org.omg.CORBA.Object

    wf=w.resolve_initial_references("NameService");

    NamingContextExt ncref=NamingContextExtHelper.narrow(wf);

    String name="Weather";

    wt=WeatherHelper.narrow(ncref.resolve_str(name));

    System.out.println("Obtained Handle on Object Server"+wt);

    System.out.println("\t WEATHER FORECASTING");

    System.out.println("\t***********************");

    wt.call(20.0);

    for(i=0;i

  • 7/31/2019 MWT Record 2011-2012

    70/73

    System.out.println(wc[i]);

    System.out.println("*******************");

    for(j=0;jMax) {

    Max=current; }

    else if(current

  • 7/31/2019 MWT Record 2011-2012

    71/73

    { return current; }

    public void call(double f)

    { Min=Max=current=f; }

    public void shutdown()

    { w.shutdown(false); } }

    public class WeatherServer {

    public static void main(String args[]) {

    try {

    ORB w=ORB.init(args,null);

    POA wpoa=POAHelper.narrow(w.resolve_initial_references("RootPOA"));

    wpoa.the_POAManager().activate();

    WeatherImp w1=new WeatherImp();

    w1.setORB(w);

    org.omg.CORBA.Object ref1=wpoa.servant_to_reference(w1);

    Weather wref=WeatherHelper.narrow(ref1);

    org.omg.CORBA.Object wf=w.resolve_initial_references("NameService");

    NamingContextExt ncref=NamingContextExtHelper.narrow(wf);

    String name="Weather";

    NameComponent path[]=ncref.to_name(name);

    ncref.rebind(path,wref);

    System.out.println("SERVER READY AND WAITING!!");

    w.run();

    }

    catch(Exception e)

    {

    System.out.println(e);

    }

    }

    }

    - 71 -

  • 7/31/2019 MWT Record 2011-2012

    72/73

    SCREENOUTPUT:

    E:\Weather>idlj Weather.idl

    E:\Weather>idlj fall Weather.idl

    E:\Weather>cd WeatherApp

    E:\Weather\WeatherApp>javac *.java

    Server:

    E:\Weather>javac Weather_ser.java

    E:\Weather>java Weather_ser

    Hello!!! SERVER READY AND WAITING!!

    E:\Weather>

    Client:

    E:\Weather>javac Weather_clnt.java

    E:\Weather>java Weather_clnt

    Obtained Handle on Object

    Server IOR:000000000000001b49444c3a57656174686572417070

    2f576561746865723a312e300000000000010000000000000086000102000000000d313

    9322e3136 382e362e3430000005d500000031afabcb0000000020909d99 c400000001000000000000000100000008526f6f74504f41000000000800000001000000000

    a000000000000020000000100000020000000000001000100000002050100010001002

    000010109000000010001010000000026000000020002

    WEATHER FORECASTING

    ***********************

    Chennai

    *******************

    Max Temp: 25.0

    Min Temp: 18.0

    Current Temp: 21.0

    Mumbai

    - 72 -

  • 7/31/2019 MWT Record 2011-2012

    73/73

    *******************

    Max Temp: 25.0

    Min Temp: 11.0

    Current Temp: 12.0

    Delhi

    *******************

    Max Temp: 25.0

    Min Temp: 11.0

    Current Temp: 17.0

    E:\Weather>