Java implementation class MSN, QQ Friends on-line notification interface

Source: Internet
Author: User

I believe that everyone has used msn,qq such as real-time chat software, for their friends on-line hint function is not unfamiliar? From the bottom right corner of the screen pop-up a small interface, slowly rise, and finally disappear. Can we make the same function in our own programs? Yes! The author now uses Java and Eclipse's SWT user interface components to implement this function.

What is SWT?

SWT was originally the Eclipse project team for the development of the Eclipse IDE written by the graphical interface API, runtime, first to determine whether the machine has the same interface elements, if there is a direct call to display, if not only to simulate the display. Its operating mechanism makes the speed much faster than awt,swing.

For more information please see: HTTP://WWW.ECLIPSE.ORG/SWT

Writing ideas

First get the user screen size, with the screen height minus the height of the popup interface to compute the popup interface's highest position on the screen (stop moving when the interface moves to this position).

Rectangle area = Display.getDefault().getClientArea();
int upPosition = area.height - 100;

The initial position of the popup interface is computed using the height of the screen plus the popup interface (not visible when initializing, then slowly moving up to the upposition point and then disappearing after a few seconds).

int downposition = area.height + 100;

Move the position we use the thread to implement, when the interface is initialized, call the start () method to run the thread, in the loop to determine whether the size of downposition is less than upposition, if less than the description has not yet to stop, Set the border of the popup interface to downposition and pause for 10 milliseconds, indicating that the popup interface has moved to its highest position if downposition is larger than upposition. Call sleep () pause for 5 seconds before closing the interface and exiting the program. It's so simple, OK, let ' s go! The entire program code is given below:

Describe:

(Test as the main interface, click the button above, call popup in the lower right corner, like MSN and QQ the same popup interface.) )

Figure I for the implementation of the source code, figure II for the modified interface (and QQ is a bit like it.) )

Figure I

Figure II

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.