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