1. Callback (CallBack) or in C language called the hook function (hook) is also called: Template method mode
Code implementation:
Code 1
------------------------------------------------------------
Package edu.neuq.oop.callback;
Import Java.awt.Frame;
public class Paintframe {
public static void Drawframe (MyFrame f) {
SYSTEM.OUT.PRINTLN ("Boot thread");
SYSTEM.OUT.PRINTLN ("increased circulation");
SYSTEM.OUT.PRINTLN ("View message stack");
F.paint ();//Draw the window here is the hook function, through the concept of polymorphism can be implemented to draw a variety of sub-class window
System.out.println ("Start cache, increase efficiency");
}
public static void Main (string[] args) {
Drawframe (New GameFrame02 ());
}
}
Class GameFrame01 extends myframe{
public void paint () {
System.out.println ("Gameframe01.paint ()");
System.out.println ("Picture Window");
}
}
Class GameFrame02 extends myframe{
public void paint () {
System.out.println ("Gameframe02.paint ()");
System.out.println ("Picture Window");
}
}
Code 2
--------------------------------------------------------------------------
Package edu.neuq.oop.callback;
Import Java.awt.Graphics;
public class MyFrame {
public void paint () {
System.out.println ("Draw my Window");
}
}
---------------------------------------------------------------
Implementation of callbacks for Java programs