简体   繁体   中英

Steps to run applet on web browser (connect applet program to html) using Eclipse

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM