Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2007, 08:31 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hook method

hai,what's hook method? please tell me and give some examples in java program!
thanks!
 
Old April 27th, 2007, 09:35 AM
Authorized User
 
Join Date: Nov 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I understand it, a hook method is a method that does nothing other than returning to its caller. For example, this is a hook method:

void doNothing( String unusedArg){ return; }

Hook methods are typically defined in what are called ‘adaptor classes’ which are classes that implement interfaces by overriding a number of abstract methods inherited from an interface with hook methods. The use of such an adaptor class is for when you want a subclass to implement an interface but you do not intend to make your program use all the methods in the interface - you intend to use only some of these methods, and so you do not want to clatter up the code in the subclass with overriding methods which you are sure will never be used. In this situation, rather than make a class implement an interface directly, you can make the class extend the corresponding adaptor class (which implements that interface with hook methods) to avoid such clatter. An example of such an adaptor class is the MouseAdaptor class which is in the package java.awt.event and has code (excluding comments):

public abstract class MouseAdapter implements MouseListener {
    public void mouseClicked(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
}

All the hook methods above overrides the abstract methods inherited from MouseListener interface.

                Andrew:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse hook question dartcoach VB How-To 1 September 12th, 2007 08:30 AM
USB devices connect Hook -- ??? Demokratizator C# 0 June 17th, 2006 12:34 PM
how can i call hook function to a specified window pradpb999 Access 0 December 30th, 2005 01:34 AM
global mouse hook G_Zola General .NET 2 May 15th, 2005 08:11 PM
Internet Events Hook SpyEyes Pro VB 6 0 December 15th, 2004 06:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.