Java Irregular windows

Source: Internet
Author: User

You want to create a desktop program, but do not want to use the default window, but instead use some irregular pictures (pictures with transparent pixels, such as PNG). It is suggested to use the Setwindowshape (Window Arg0,shape arg1) method of the Awtutilities class, but this method can only load one picture, and I want to make a window with multiple images. Although the simplest method is the direct PS synthesis, but in order to facilitate the movement of a picture later, I still use dynamic loading method, may be less than the number of netizens have such a demand, it is difficult to find such an example. At first thought a lot of ways to achieve, but all do not achieve the desired effect. Finally found in the Awtutilities class there is another method--awtutilities.setwindowopaque (this, false), the window becomes transparent, and then draw the picture that needs to be displayed, part of the code is as follows

        /**  * Initialization window */private void Initialize () {//TODO auto-generated method Stubthis.setalwaysontop (True); This.setsize (T Oolkit.getdefaulttoolkit (). Getscreensize (). Width,toolkit.getdefaulttoolkit (). Getscreensize (). height);// Sets the disable form adornment so that the default form structure this.setundecorated (TRUE) is canceled;//Initializes the origin of the window to move the point origin = new dot (); Awtutilities.setwindowopaque (this, false);//Set Form visibility awtutilities.setwindowopacity (this, 1f);// Form Center This.setlocationrelativeto (null); This.setdefaultcloseoperation (jframe.exit_on_close); This.setVisible (True) ;}


@Override public void Paint (Graphics g) {super.paint (g);               Draws the desired picture in the specified place for (Imagebean Mimagebean:mimagebeans) {g.drawimage (Mimagebean.getimage (), Mimagebean        . GetX (), mimagebean.gety (), NULL); }    }



Java Irregular windows

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.