Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Applet Libraries Question

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java Applet Libraries Question

    Hi All,

    I have been investigating java applets a bit. All the tutorials seem to be using the java.awt, java.applet and swing for the GUI. A few people in the industry tell me that swing is not really used in client facing applications anymore. Are there other libraries that java applets are made with beside swing? I would hate to learn an old technique/technology. Thanks for your input.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Applet Libraries Question

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

  3. #3
    Member
    Join Date
    Sep 2018
    Posts
    32
    Thanks
    0
    Thanked 9 Times in 6 Posts

    Default Re: Java Applet Libraries Question

    Java Applet Basics
    Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag and hosted on a web server.

    Applets are used to make the web site more dynamic and entertaining.

    Some important points :

    All applets are sub-classes (either directly or indirectly) of java.applet.Applet class.
    Applets are not stand-alone programs. Instead, they run within either a web browser or an applet viewer. JDK provides a standard applet viewer tool called applet viewer.
    In general, execution of an applet does not begin at main() method.
    Output of an applet window is not performed by System.out.println(). Rather it is handled with various AWT methods, such as drawString().
    Life cycle of an applet :


    It is important to understand the order in which the various methods shown in the above image are called. When an applet begins, the following methods are called, in this sequence:

    1. init( )
    2. start( )
    3. paint( )





    When an applet is terminated, the following sequence of method calls takes place:
    1. stop( )
    2. destroy( )
    Let’s look more closely at these methods.

    init( ) : The init( ) method is the first method to be called. This is where you should initialize variables. This method is called only once during the run time of your applet.
    start( ) : The start( ) method is called after init( ). It is also called to restart an applet after it has been stopped. Note that init( ) is called once i.e. when the first time an applet is loaded whereas start( ) is called each time an applet’s HTML document is displayed onscreen. So, if a user leaves a web page and comes back, the applet resumes execution at start( ).
    paint( ) : The paint( ) method is called each time an AWT-based applet’s output must be redrawn. This situation can occur for several reasons. For example, the window in which the applet is running may be overwritten by another window and then uncovered. Or the applet window may be minimized and then restored.
    paint( ) is also called when the applet begins execution. Whatever the cause, whenever the applet must redraw its output, paint( ) is called.

    The paint( ) method has one parameter of type Graphics. This parameter will contain the graphics context, which describes the graphics environment in which the applet is running. This context is used whenever output to the applet is required.

    stop( ) : The stop( ) method is called when a web browser leaves the HTML document containing the applet—when it goes to another page, for example. When stop( ) is called, the applet is probably running. You should use stop( ) to suspend threads that don’t need to run when the applet is not visible. You can restart them when start( ) is called if the user returns to the page.
    destroy( ) : The destroy( ) method is called when the environment determines that your applet needs to be removed completely from memory. At this point, you should free up any resources the applet may be using. The stop( ) method is always called before destroy( ).
    Creating Hello World applet :

    Let’s begin with the HelloWorld applet :

    // A Hello World Applet
    // Save file as HelloWorld.java

    import java.applet.Applet;
    import java.awt.Graphics;

    // HelloWorld class extends Applet
    public class HelloWorld extends Applet
    {
    // Overriding paint() method
    @Override
    public void paint(Graphics g)
    {
    g.drawString("Hello World", 20, 20);
    }

    --- Update ---

    Java Applet Basics
    Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag and hosted on a web server.

    Applets are used to make the web site more dynamic and entertaining.

    Some important points :

    All applets are sub-classes (either directly or indirectly) of java.applet.Applet class.
    Applets are not stand-alone programs. Instead, they run within either a web browser or an applet viewer. JDK provides a standard applet viewer tool called applet viewer.
    In general, execution of an applet does not begin at main() method.
    Output of an applet window is not performed by System.out.println(). Rather it is handled with various AWT methods, such as drawString().
    Life cycle of an applet :


    It is important to understand the order in which the various methods shown in the above image are called. When an applet begins, the following methods are called, in this sequence:

    1. init( )
    2. start( )
    3. paint( )





    When an applet is terminated, the following sequence of method calls takes place:
    1. stop( )
    2. destroy( )
    Let’s look more closely at these methods.

    init( ) : The init( ) method is the first method to be called. This is where you should initialize variables. This method is called only once during the run time of your applet.
    start( ) : The start( ) method is called after init( ). It is also called to restart an applet after it has been stopped. Note that init( ) is called once i.e. when the first time an applet is loaded whereas start( ) is called each time an applet’s HTML document is displayed onscreen. So, if a user leaves a web page and comes back, the applet resumes execution at start( ).
    paint( ) : The paint( ) method is called each time an AWT-based applet’s output must be redrawn. This situation can occur for several reasons. For example, the window in which the applet is running may be overwritten by another window and then uncovered. Or the applet window may be minimized and then restored.
    paint( ) is also called when the applet begins execution. Whatever the cause, whenever the applet must redraw its output, paint( ) is called.

    The paint( ) method has one parameter of type Graphics. This parameter will contain the graphics context, which describes the graphics environment in which the applet is running. This context is used whenever output to the applet is required.

    stop( ) : The stop( ) method is called when a web browser leaves the HTML document containing the applet—when it goes to another page, for example. When stop( ) is called, the applet is probably running. You should use stop( ) to suspend threads that don’t need to run when the applet is not visible. You can restart them when start( ) is called if the user returns to the page.
    destroy( ) : The destroy( ) method is called when the environment determines that your applet needs to be removed completely from memory. At this point, you should free up any resources the applet may be using. The stop( ) method is always called before destroy( ).
    Creating Hello World applet :

    Let’s begin with the HelloWorld applet :

    // A Hello World Applet
    // Save file as HelloWorld.java

    import java.applet.Applet;
    import java.awt.Graphics;

    // HelloWorld class extends Applet
    public class HelloWorld extends Applet
    {
    // Overriding paint() method
    @Override
    public void paint(Graphics g)
    {
    g.drawString("Hello World", 20, 20);
    }

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Java Applet Libraries Question

    I am new to the forum as you are. But on other forums they usually discourage replying to old threads (this one was 4 years old). And it would be much easier to refer to some outside reference (like the Java Tutorials) instead of going into all that detail on a reply (an article might be a better place for that). And finally, applets are going by the way of the dodo. Most browsers no longer support them (as the OP may now realize) due to security concerns.

    Regards,
    Jim

Similar Threads

  1. Referencing libraries in java
    By pyler in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 30th, 2013, 02:08 PM
  2. java libraries
    By pettiville in forum The Cafe
    Replies: 1
    Last Post: June 28th, 2013, 05:35 PM
  3. Using C Libraries in Java Project
    By x34 in forum Java Native Interface
    Replies: 1
    Last Post: September 25th, 2012, 02:01 PM
  4. Question about project libraries
    By xMKx in forum Java Theory & Questions
    Replies: 0
    Last Post: August 12th, 2012, 11:33 PM
  5. java applet program question (on getting path fails)
    By hellocheese in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 30th, 2011, 04:34 PM