Java implementation class MSN, QQ friends online notification interface

xiaoxiao2021-03-06  24

I believe everyone has used instant chat software such as MSN and QQ. Is it not strange to their friends? Pop up a small interface from the lower right corner of the screen, slowly increase, and finally disappear. Can we make the same functionality in your own procedure? can! The author is now implemented with the SWT user interface component of Java and Eclipse implementation. What is SWT? SWT originally the Eclipse project group to develop the graphical interface API written by Eclipse IDE, when running, the local element has the same interface element, if there is, call the display directly, if there is no simulation display. Its operational mechanism makes a lot of speed than AWT, Swing. Learn more: http://www.eclipse.org/swt Writing Thought First get the user screen size, use the screen height to reduce the high level of the Popup interface to the highest position displayed on the screen display (when the interface moves to this Stop movement when the location is positioned).

Rectangle area = display.getDefault (). GetClientarea (); int upposition = area.Height - 100; calculates the initial position of the POPUP interface with the height of the POPUP interface (not visible when initialization, then move slowly After the UPPosition point is stopped, the move will be disappeared after a few seconds).

INT DownPosition = Area.height 100; Mobile Location We use thread implementation, when the initialization interface is called, call the start () method to run this thread. Cycle whether the size of the DownPosition is less than UPPosition if it is less than that is not stopped. At the time, set the border of the Popup interface to DownPosition and pause 10 milliseconds, if DownPosition is greater than UPPosition, the Popup interface has moved to the highest position. Call SLEEP () Pause 5 seconds to close the interface and exit the program. Just, OK, Let's Go! The entire program code is given below: Description: (TEST is the main interface, click the button above, call Popup to display the Popup interface like MSN and QQ in the lower right corner.) Figure 1 Implementation in the code, Figure 2 is a modified interface (and a bit like QQ.)

Figure 1

Source code:

// Test.java// main interface, where only one button, call POPUP when clicking on the lower right corner display of the POPUP interface like MSN and QQ. import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets .Display; import.widgets.shell; public class test {public static void main (string [] args) {final display display = new display (); shell shell = new shell (); shell.setText (SHELL.SETTEXT "aaa"); shell.setsize (250, 150); Final Button Button = New Button (shell, swt.none); Button.SetBounds (50, 20, 100, 25); button.setText ("Button"); // Monitor the Button event, call the popup class to display the Popup interface when the user clicks. Button.addSelectionListener (New SelectionAdapter () {Public Void WidgetSelected (SelectionEvent E) {// Instantizes the Popup class, the constructor is prompt information that appears in the POPUP interface. Popup popup = new popup ("Your friend XXX is online.

"); Popup.start ();}}); shell.Open (); while (! Shell.iedisposed ()) {if (! Display.readDispatch ()) {Display.Sleep ();}} DISPLAY.Dispose ();}} // Popup.java// Implementing friends like MSN, QQ notify popupimport org.eclipse.swt.Eclipse.swt.graphus.ectangle; import org.eclipse.swt.widgets .Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class Popup extends Thread {Shell shell; protected int moveStep = 2; // moving each pixel protected int upPosition ; // can move to the top coordinate protected int downloadposition; // Current Popup Border coordinate protected int in 坐 坐 坐 坐 {= = = = {{{;;; Text = new text (shell, swt.multi | swt.wrap); text.setBounds (10, 20, 180, 80); text.setBackground (); text.setText (message); // Take Pentangle area = display.getdefault (). GetClientarea (); upposition = area.height - 100; // calculate the highest position of the popup interface on the screen display DOWNPSITION = area.Height 100; // calculate the Popup interface Initial location LeftPosition = Area .width - 180; shell.setsize (180, 100); // Initialization Popup position shell.setLocation; shell.Open ();} public void ruy () {display display = shell.getDisplay (); While (TRUE) {Try {thread.sleep (10); // Determine if the current location is less than the highest position that can appear, and if it is less than, it will be moved upward. IF ((DOWNPOSITION - MOVESTEP)> UPPSITION) {Display.AssYncexec (New Runnable () {public void Run () {shell.setLocation (leftPosition, DownPosition- MoveStep); DownPosition - = MoveStep;}}); // At this time It has been moved to the highest position, after 5 seconds, turn off the window and exit.

转载请注明原文地址:https://www.9cbs.com/read-43731.html

New Post(0)