HOWTO: Enabling Hot-Tracking in an AFC UIPushButton

Last reviewed: January 27, 1998
Article ID: Q179852
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java
  • SDK for Java, versions 2.0, 2.01

SUMMARY

The Microsoft Application Foundation Classes (AFC) includes the ability to enable hot-tracking by overriding the setHot() method.

MORE INFORMATION

The sample code below demonstrates overriding the "setHot(boolean hot)" method, changing the color of the component inside a UIPushButton when the cursor is over the button.

Sample Code

   import com.ms.ui.*;
   import com.ms.fx.*;

   public class HotTrackDemo {
     public static void main(String args[])
     {
       UIFrame frame = new UIFrame("HotPushButton Example");
       frame.setLayout(new UIGridLayout(3,0));
       frame.setSize(320,200);
       frame.setVisible(true);
       HotPushButton btn1=new HotPushButton("BUTTON1");
       HotPushButton btn2=new HotPushButton("BUTTON2");
       btn2.setColors(FxColor.green,FxColor.lightGray);
       frame.add(btn1);
       frame.add(btn2);
     }
   }

   class HotPushButton extends UIPushButton {
     java.awt.Color colorNorm=java.awt.Color.black;
     java.awt.Color colorHot=java.awt.Color.red;
     public HotPushButton(String value) {
       super(value);
     }
     public HotPushButton(IUIComponent comp) {
       super(comp);
     }
     public void setColors(java.awt.Color hot,java.awt.Color norm) {
       colorHot=hot;
       colorNorm=norm;
       setHot(isHot());
     }
     public void setHot(boolean hot) {
       super.setHot(hot);
       setForeground(hot?colorHot:colorNorm);  // Change color of component
       invalidateAll();
     }
   }

REFERENCES

For more information please see the Microsoft SDK for Java 2.0x documentation, available at http://www.microsoft.com/java/sdk/.

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: hot tracking afc uipushbutton
Keywords : AWTPkg
Technology : kbInetDev internet
Version : WINDOWS:2.0,2.01
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.