Results 1 to 7 of 7

Thread: Applets

  1. #1
    hackr is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default Applets

    Java Applet

    Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It runs inside the browser and works at client side.
    Learn Java in detail here Nothing to see here

    Advantage of Applet

    There are many advantages of applet. They are as follows:

    It works at client side so less response time.
    Secured
    It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc.
    Drawback of Applet

    Plugin is required at client browser to execute applet.


    Do You Know
    Who is responsible to manage the life cycle of an applet ?
    How to perform animation in applet ?
    How to paint like paint brush in applet ?
    How to display digital clock in applet ?
    How to display analog clock in applet ?
    How to communicate two applets ?
    Hierarchy of Applet

    hierarchy of applet
    As displayed in the above diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component.
    Lifecycle of Java Applet

    Applet is initialized.
    Applet is started.
    Applet is painted.
    Applet is stopped.
    Applet is destroyed.
    Lifecycle methods for Applet:

    The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet.

    java.applet.Applet class

    For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.

    public void init(): is used to initialized the Applet. It is invoked only once.
    public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet.
    public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
    public void destroy(): is used to destroy the Applet. It is invoked only once.
    java.awt.Component class

    The Component class provides 1 life cycle method of applet.

    public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc.
    Who is responsible to manage the life cycle of an applet?

    Java Plug-in software.

    How to run an Applet?

    There are two ways to run an applet

    By html file.
    By appletViewer tool (for testing purpose).
    Simple example of Applet by html file:

    To execute the applet by html file, create an applet and compile it. After that create an html file and place the applet code in html file. Now click the html file.

    //First.java
    import java.applet.Applet;
    import java.awt.Graphics;
    public class First extends Applet{

    public void paint(Graphics g){
    g.drawString("welcome",150,150);
    }

    }
    Note: class must be public because its object is created by Java Plugin software that resides on the browser.

    myapplet.html

    <html>
    <body>
    <applet code="First.class" width="300" height="300">
    </applet>
    </body>
    </html>
    Last edited by Tolls; 04-20-2017 at 09:32 AM. Reason: Removed self promotion

  2. #2
    hackr is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default Applets

    The "Hello World" Applet

    By following the steps on this page, you can create and use an applet. If you aren't interested in applets, you might want to skip ahead to the Writing Java Programs(in the Writing Java Programs trail) trail.
    Learn Java in detail here Nothing to see here

    Create a Java Source File

    Create a file named HelloWorld.java with the Java code shown here:
    import java.applet.Applet;
    import java.awt.Graphics;

    public class HelloWorld extends Applet {
    public void paint(Graphics g) {
    g.drawString("Hello world!", 50, 25);
    }
    }
    Compile the Source File

    Compile the source file using the Java compiler.
    If the compilation succeeds, the compiler creates a file named HelloWorld.class in the same directory (folder) as the Java source file (HelloWorld.java). This class file contains Java bytecodes.

    If the compilation fails, make sure you typed in and named the program exactly as shown above. If you can't find the problem, see Common Compiler and Interpreter Problems(in the Getting Started trail).

    Create an HTML File that Includes the Applet

    Using a text editor, create a file named Hello.html in the same directory that contains HelloWorld.class. This HTML file should contain the following text:
    <HTML>
    <HEAD>
    <TITLE> A Simple Program </TITLE>
    </HEAD>
    <BODY>

    Here is the output of my program:
    <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
    </APPLET>
    </BODY>
    </HTML>
    Run the Applet

    To run the applet, you need to load the HTML file into an application that can run Java applets. This application might be a Java-compatible browser or another Java applet viewing program, such as the Applet Viewer provided in the JDK. To load the HTML file, you usually need to tell the application the URL of the HTML file you've created. For example, you might enter something like the following into a browser's URL or Location field:
    file:/home/kwalrath/HTML/Hello.html
    Once you've successfully completed these steps, you should see something like this in the browser window:
    Last edited by Tolls; 04-20-2017 at 09:34 AM.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Question about applets

    Seems a bit pointless in this day and age covering applets.
    Your single drawback is massive as the plugin has been/is being withdrawn from all major browsers.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Create Java Applet

    Please don't plug your site here.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,942
    Rep Power
    30

    Default Re: Applets

    Moved and merged
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,189
    Rep Power
    12

    Default Re: Applets

    So now some person is whose user id is hackr, doesn't understand Java syntax, and is plugging obsolete Java capabilities is trying to teach Java. Sounds like a winning trifecta.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,964
    Rep Power
    7

    Default Re: Applets

    Quote Originally Posted by jim829 View Post
    So now some person is whose user id is hackr, doesn't understand Java syntax, and is plugging obsolete Java capabilities is trying to teach Java. Sounds like a winning trifecta.

    Regards,
    Jim
    And he posts Visual Basic crap. Can someone wave the banstick?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

Similar Threads

  1. Applets
    By hackr in forum Forum Lobby
    Replies: 1
    Last Post: 04-20-2017, 09:34 AM
  2. Applets
    By MBD in forum New To Java
    Replies: 2
    Last Post: 11-02-2011, 03:49 AM
  3. I need help with Applets
    By ProgrammingPup in forum Advanced Java
    Replies: 1
    Last Post: 12-22-2009, 08:07 PM
  4. Can't see any Applets
    By pyr0chem in forum Java Applets
    Replies: 9
    Last Post: 12-17-2008, 04:24 AM
  5. applets on mac what´s going on?
    By willemjav in forum Java Applets
    Replies: 6
    Last Post: 04-19-2008, 07:03 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
  •