Java jfram automatic hiding

Source: Internet
Author: User

Import Java. AWT. point; import Java. AWT. rectangle; import Java. AWT. event. actionevent; import Java. AWT. event. actionlistener; import javax. swing. jframe; import javax. swing. timer; public class myframe extends jframe implements actionlistener {private rectangle rect; // The distance between the form and the left of the screen is private int left; // The distance between the form and the top of the screen is private int top; // form width private int width; // form height private int height; // place the cursor in the form private point Point; private timer = new timer (10, this); Public myframe () {timer. start ();} public void actionreceivmed (actionevent e) {left = getlocationonscreen (). x; Top = getlocationonscreen (). y; width = getwidth (); Height = getheight (); // obtain the form profile rect = new rectangle (0, 0, width, height ); // obtain the cursor position in the Form. Point = getmouseposition (); If (top <0) & isptinrect (rect, point) {// when the cursor is in the current form, and the top attribute of the form. Less than 0 // set the top attribute of the form to 0, that is, to close the upper edge of the window to the top setlocation (left, 0 );} else if (top>-5 & Top <5 &&! (Isptinrect (rect, point) {// when the distance between the upper border of the form and the top of the screen is less than 5, // and the mouse does not hide the QQ form to the top of the screen. setlocation (left, 5-height );}} /*** determine whether a vertex is in a rectangle ** @ Param rect: rectangle object * @ Param point: Point Object * @ return: if true is returned in a rectangle, false */Public Boolean isptinrect (rectangle rect, point) {If (rect! = NULL & point! = NULL) {int X0 = rect. x; int Y0 = rect. y; int X1 = rect. width; int Y1 = rect. height; int x = point. x; int y = point. y; return x> = x0 & x <X1 & Y> = y0 & Y <Y1;} return false;} public static void main (string [] ARGs) {myframe frame = new myframe (); frame. settitle ("test"); frame. setsize (400,300); frame. setlocation (400,300); frame. setvisible (true); frame. setdefaclocloseoperation (jframe. exit_on_close );}}

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.