1 书写表白语句的 Cadre (渐入功能 渐入功能
package com.wanju.blessing; import java.awt.color; Importer Java.awt.Container; import java.awt.dimension; Importer java.awt.font; import java.awt.graphics; import java.awt.image; import java.awt.toolkit; Importer java.awt.event.mousEadapter; Importer java.awt.event.mousevent; Importer java.net.url; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jpanel; importer shen.panel; import com.sun.awt.awtutilities; classe publique ShowFrame étend JFrame {public showFrame () {this.setSize (600, 500); Dimension ScreenSize = Toolkit.getDefaultToolkit (). GetScreenSize (); Dimension FrameSize = this.getSize (); this.setUndeCorated (true); this.setLocation ((screensize.width - framesize.width) / 2, (screensize.height - frameSize.height) / 2); this.setDefaultCloseOperation (jframe.exit_on_close); Conteneur conteneur = this.getContentPane (); // awtutilities.setwindowoPaque (this, true); Awtutilities.setwindowoPacity (ceci, 0,01f); contener.add (new MyPanel (this)); this.setbackground (null); this.setVisible (true); new fadeout (this) .start (); } public static void main (string [] args) {showFrame showFrame = new showFrame (); }} class MyPanel étend jpanel {fond d'image privé; Frame JFrame; public mypanel (Final JFrame Frame) {this.frame = frame; try {url url = panneau.class.getResource ("a.jpg"); ImageIcon icon = new ImageIcon (URL); fond = icon.getImage (); // background = imageo.read (nouveau fichier ("d: //workspace//maven//blessing//src//shen//b.jpg")); this.addmouseListener (new MouseAdapter () {@Override public void Mouseclicked (Mouseevent e) {super.mouseclicked (e); // new fadeout (mypanel.this.frame) .start (); frame.setVisible (false); frame.dispose ();}}); } catch (exception e) {e.printStackTrace (); }} Protected void PaintComponent (Graphics G) {super.paintComponent (g); G.DrawImage (arrière-plan, 0,0,666,666, null); g.setColor (Color.Red); g.setfont (new Font ("", font.bold, 15)); G.Drawstring ("祝愿宝儿永远幸福的像花儿一样", 60, 280); }} classe Fadeout étend Thread {private jFrame wnd; public fadeout (jframe wnd) {this.wnd = wnd; } public void run () {try {for (int i = 0; i <50; i ++) {thread.sleep (50); Awtutilities.setwindowopacity (wnd, i / 50f); }} catch (exception ex) {ex.printStackTrace (); }}} 2 玫瑰花 Cadre
Package Shen; import java.awt.eventqueue; import javax.swing.jframe; import com.sun.awt.awtutilities; Le cadre de classe publique étend JFrame {private statique final long SerialVersionUID = 7517576070147366983l; Public Frame () {Settitle ("png 透明窗体"); setDefaultCloseOperation (jframe.exit_on_close); SETUDECORATED (true); setSize (666, 666); setLocationRelativeto (null); Awtutilities.setwindowopaque (ceci, false); setContentPane (nouveau panneau (this)); addMouseListener (new MoveWindow (this)); } public static void main (String [] args) {eventQueue.invokelater (new Runnable () {@Override public void run () {new frame (). setVisible (true);}}); }}3
Package Shen; import java.awt.graphics; import java.awt.image; Importer java.awt.point; Importer java.awt.event.mousEadapter; Importer java.awt.event.mousevent; Importer java.net.url; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jpanel; import com.sun.awt.awtutilities; import Shen.panel.fadeout; La classe publique MoveWindow étend MousEadapter {Private Point en dernier; cadre JFrame privé; public MoveWindow (JFrame frame) {this.frame = frame; } public void Mousdressressed (MouseEvent e) {Last = e.getLocationOnScreen (); } public void MouseLelent (MouseEvent e) {Point Point = e.getLocationOnScreen (); Point fpoint = frame.getLocation (); frame.setLocation (fpoint.x + point.x - last.x, fpoint.y + point.y - last.y); dernier = point; }} 4
Package Shen; import java.awt.graphics; import java.awt.image; Importer java.awt.event.mousEadapter; Importer java.awt.event.mousevent; Importer java.net.url; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jpanel; import com.sun.awt.awtutilities; import com.wanju.blessing.showframe; Le panneau de classe publique étend JPanel {fond d'image privé; Jframe frame = null; public jFrame getFrame () {return frame; } public void setFrame (JFrame frame) {this.frame = frame; } panneau public (JFrame frame) {this.frame = frame; try {// background = imageo.read (new File ("d: //workspace//maven//blessing//src//shen//window.png")); // background = imageo.read (nouveau fichier ("d: //workspace//maven//blessing//src//shen//b.jpg")); Url url = panneau.class.getResource ("c.jpg"); ImageIcon icon = new ImageIcon (URL); fond = icon.getImage (); // background = imageo.read (nouveau fichier ("d: //workspace//maven//blessing//src//shen//b.jpg")); this.AddMouseListener (new MouseAdapter () {@Override public void Mouseclicked (Mouseevent e) {super.mouseclicked (e); new fadeout (panneau.this.frame) .start ();}}); } catch (exception e) {e.printStackTrace (); }} classe Fadeout étend Thread {private jFrame wnd; public fadeout (jframe wnd) {this.wnd = wnd; } public void run () {try {for (int i = 50; i> 0; i--) {thread.sleep (50); Awtutilities.setwindowopacity (wnd, i / 50f); }} catch (exception ex) {ex.printStackTrace (); } wnd.setVisible (false); wnd.dispose (); Nouveau showframe (); }} Protected void PaintComponent (Graphics G) {super.paintComponent (g); G.DrawImage (arrière-plan, 0,0,666,666, null); }}5 : :
以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。