Demo of Java Framework methods

Source: Internet
Author: User

It's interesting to watch the actual workings of the framework approach (this example uses only init (), Start () and stop (), because paint () and destroy () are very simple and easy to grasp. The following patches will track the number of times these method calls and display them with paint ():

: Applet3.java
//Shows Init (), Start () and stop () activities
import java.awt.*;
Import java.applet.*;

public class Applet3 extends Applet {
  String s;
  int inits = 0;
  int starts = 0;
  int stops = 0;
  public void init () {inits++;}
  public void Start () {starts++;}
  public void Stop () {stops++;}
  public void Paint (Graphics g) {
    s = "inits:" + inits + 
      ", starts:" + starts +
      ", stops:" + stops;
    g.DrawString (S, a);
  }
///:~

Normally, when we overload a method, it is important to check whether we need to invoke the underlying class version of the method. For example, you might need to invoke super.init () when using init (). However, applet documentation specifically points out that Init (), Start (), and stop () are not useful in applets, so there is no need to invoke them here.
To experiment with this program, you'll find that if you minimize a Web browser, or overwrite it with another window, you can't call Stop () and start () (This behavior changes with different implementations; Consider comparing the behavior of the Web browser with the behavior of the program Viewer). The only occurrence of the invocation is when we move to a different Web page and then return the page that contains the program slice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.