Results 1 to 5 of 5
  1. #1
    elururajesh3 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default How to run applet in a web Browser?

    We are trying to execute the applet using web browser, while we are executed by the appletviewer it is working fine and is connecting the database and getting printing the values of the table in the applet. But when we tried to execute the same using web browser it is not. Please reply with solution asap.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: How to run applet in a web Browser?

    Can you show me that how did you run your applet on the web browser? How did you integrate?

  3. #3
    elururajesh3 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: How to run applet in a web Browser?

    Below code is executed by c:\>appletviewer login.html is working properly it is giving database values as phone number and name.
    In web browser in the address bar : c:\login.html when i hit this address it is giving background color page with labels and phone number as "0" and name as "null".
    //login.java file
    import java.awt.*;
    import java.applet.*;
    import java.sql.*;

    /**
    * Class login - write a description of the class here
    *
    * @author (your name)
    * @version (a version number)
    */
    public class login extends Applet
    { int ph;
    String adr;
    // instance variables - replace the example below with your own
    Connection con;
    Statement st;
    ResultSet rs;

    public void init()
    {


    setBackground(Color.pink);
    display();


    // provide any initialisation necessary for your JApplet
    }

    public void display()
    {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:tee");

    st=con.createStatement();
    rs=st.executeQuery("select * from info");
    while(rs.next())
    {
    adr=rs.getString("Name");
    ph=rs.getInt("Teleno");
    repaint();
    }
    }

    catch(Exception e)
    {
    System.out.println("Exception:"+e);
    }
    }
    /**
    * Paint method for applet.
    *
    * @param g the Graphics object for this applet
    */
    public void paint(Graphics g)
    {
    // simple text displayed on applet
    //g.setBackground(Color.pink);
    //g.setColor(Color.black);
    g.setColor(Color.black);

    g.drawString("phone_no="+ph,20, 20);
    // g.setColor(Color.blue);
    g.drawString("Address="+adr,30, 40);

    }

    }
    login.html
    <html>
    <body>
    <applet code="login.class" width=700 height=700>
    </applet>
    </body>
    </html>

  4. #4
    elururajesh3 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: How to run applet in a web Browser?

    By grant the permission of the sun.jdbc.odbc read permission that problem has been solved, now I am able to see the applet in web browser with database field values.
    I have one question, I am doing one project based on applets on a single machine.In that I would like to protect each applet by embedding code in each applet, something like reading a parameter and if its value is null then it will take me to login page. For this modification any one have thoughts about this please reply back.

  5. #5
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default Re: How to run applet in a web Browser?

    you have to make an HTML file for that,for your case,it's like-

    <html>
    <applet code="here comes the name of the .class file that contains your code" height =800 width=800>
    <param name="parametername that you want to pass to applet" value=the value that is passed to applet >
    </applet>
    </htm>

    save this file using .html extension and save it in the same folder that contains your .class file.......then open the .html file using web browser and bravo!!!!

Similar Threads

  1. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 06:47 PM
  2. Browser not loading applet
    By jchapuran in forum Java Applets
    Replies: 0
    Last Post: 01-16-2011, 08:08 PM
  3. No sound when applet is in browser
    By Ambergahill in forum New To Java
    Replies: 5
    Last Post: 11-21-2010, 06:40 AM
  4. Applet with Images in Browser
    By baron in forum Eclipse
    Replies: 0
    Last Post: 09-20-2009, 10:06 PM
  5. applet won't run in browser...
    By shwein in forum Java Applets
    Replies: 6
    Last Post: 10-17-2008, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •