0
votes

Hi friends I am new to Java. I am trying to display applet on web browser using Eclipse.

Code:

import java.applet.*;

import java.awt.*;

public class AppletDemo extends Applet{

    String msg="hello";

    public void init(){

        msg=getParameter("message");

    }

     public void paint(Graphics g){

        g.drawString(msg,80,80);

    }

}

Applet Tag:

<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<applet code="AppletDemo.class"width="350"height="350">

<param name="message"value="Welcome to the world of Applet">

</applet>

</body>

</html>

Output should be "Welcome to the world of Applet" but when I run it, no value is getting displayed.

i got output in console is:

Oct 20, 2014 12:43:39 AM org.apache.catalina.core.AprLifecycleListener init

INFO: The APR based Apache Tomcat Native library which allows optimal performance in

production environments was not found on the java.library.path: C:\Program Files\Java

\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java

/jre8/bin/client;C:/Program Files/Java/jre8/bin;C:/Program Files/Java/jre8/lib

/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32

\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_05\bin;.;C:\Users\RAJEEV4\Desktop

\eclipse-jee-kepler-SR2-win32(1)\eclipse;;.

Oct 20, 2014 12:43:40 AM org.apache.tomcat.util.digester.SetPropertiesRule begin

WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'

to 'org.eclipse.jst.jee.server:demojsp' did not find a matching property.

Oct 20, 2014 12:43:40 AM org.apache.tomcat.util.digester.SetPropertiesRule begin

WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'

to 'org.eclipse.jst.jee.server:Zdemoappletweb' did not find a matching property.

Oct 20, 2014 12:43:40 AM org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["http-bio-8080"]

Oct 20, 2014 12:43:40 AM org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["ajp-bio-8009"]

Oct 20, 2014 12:43:40 AM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 2323 ms

Oct 20, 2014 12:43:41 AM org.apache.catalina.core.StandardService startInternal

INFO: Starting service Catalina

Oct 20, 2014 12:43:41 AM org.apache.catalina.core.StandardEngine startInternal

INFO: Starting Servlet Engine: Apache Tomcat/7.0.53

Oct 20, 2014 12:43:42 AM org.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler ["http-bio-8080"]

Oct 20, 2014 12:43:42 AM org.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler ["ajp-bio-8009"]

Oct 20, 2014 12:43:42 AM org.apache.catalina.startup.Catalina start

INFO: Server startup in 1961 ms

What is the issue here?

2
even hello is not displaying?Rod_Algonquin
my question is i can run this program from cmd but how to run same program by eclips("hello" is displaying when i run directly but how to display "Welcome to the world of Applet" in eclips ) please tell me steps.....rajeev mishra
i am not getting any error..rajeev mishra
i am getting title "Insert title here" then after a box with message "error: click here for detail" then there is a message "class not found exception". @SparkOnrajeev mishra

2 Answers

0
votes
you can use this code ..


              import java.applet.Applet.*;
              import java.applet.*;
            import java.awt.*;
            public class Demo4 extends Applet
               {
                 public void paint(Graphics g)
              {
                  Font f=new Font("calibri",Font.BOLD,50);
                  g.setFont(f);
                 g.setColor(Color.red);
                g.fillRect(0,0,1400,300);
               g.setColor(Color.yellow);
               g.fillRect(0,300,1400,600);
               g.setColor(Color.green);
               g.drawString("Welcome to the world of applet",100,200);  
               }
              }
                /*<applet code="Demo4.class" WIDTH=20 HEIGHT=20>
              </applet>*/

Here thre is no need to make applet tag direct run this code..u have to foloow these rule to run

for compile- javac Demo4.java for run- appletViewer Demo4.java

you get your ans easily..and don,t forget to include commen lines of applet these are the main lines

0
votes

First compile the AppletDemo class then keep the .class and the html file in same location. Then when you open the html file if you are getting error like

Your security settings have blocked a local application from running

Then just go to

start - >control panel -> java(if unable to find type java in the search field of control panel) -> Then click on it a menu pops up go to security tab -> then make the security label to medium and ok.

Then again open the html in browser it will ask to click on run this application thats it.