1 书写表白语句的 quadro (渐入功能))
pacote com.wanju.blessing; importar java.awt.color; importar java.awt.container; importar java.awt.dimension; importar java.awt.font; importar java.awt.graphics; importar java.awt.image; importar java.awt.toolkit; importar java.awt.event.mouseAdapter; importar java.awt.event.mouseevent; importar java.net.url; importar javax.swing.imageicon; importar javax.swing.jframe; importar javax.swing.jpanel; importar shen.panel; importação com.sun.awt.awtutities; public class Showframe estende 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); Contêiner contêiner = this.getContentPane (); // awtutilities.setWindowoPaque (isto, verdadeiro); Awtutilities.setWindowOpacity (isto, 0,01f); container.add (new mypanel (this)); this.setbackground (nulo); this.setVisible (true); novo Fadeout (this) .start (); } public static void main (string [] args) {showframe showFrame = new ShowFrame (); }} classe mypanel estende JPanel {fundo privado de imagem; Quadro jframe; public mypanel (quadro final JFrame) {this.frame = frame; tente {url url = painel.class.getResource ("a.jpg"); Icon imageicon = novo imageicon (URL); Antecedentes = icon.getImage (); // background = imageio.read (novo arquivo ("d: //workspace//maven//blessing//src//shen//b.jpg")); this.AddmouseListener (new mouseAdapter () {@Override public void mouseclicked (mouseevent e) {super.mouseclicked (e); // new fadeout (mypanel.thispe.this.frame) .start (); estrutura. } catch (Exceção e) {e.printStackTrace (); }} Void PaintComponent protegido (gráficos g) {super.PaintComponent (g); G.Drawimage (Antecedentes, 0,0,666.666, NULL); g.setColor (color.red); G.SetFont (New Font ("", Font.Bold, 15)); G.DrawString ("祝愿宝儿永远幸福的像花儿一样", 60, 280); }} classe fadeout estende o 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 (Exceção ex) {ex.PrintStackTrace (); }}} 2 玫瑰花 quadro
pacote shen; importar java.awt.eventqueue; importar javax.swing.jframe; importação com.sun.awt.awtutities; A classe pública Frame estende JFRame {private estático final serialversionuid = 7517576070147366983L; public Frame () {Settitle ("png 透明窗体"); setDefaultCloseoperation (jframe.exit_on_close); setundeCorated (true); SetSize (666, 666); setLocationRelativeTo (NULL); Awtutilities.setWindowOPAQUE (isto, false); setContentPane (novo painel (this)); addmouselistener (new MoveWindow (isto)); } public static void main (string [] args) {eventQueue.invokelater (new Runnable () {@Override public void run () {new Frame (). setVisible (true);}}); }}3
pacote shen; importar java.awt.graphics; importar java.awt.image; importar java.awt.point; importar java.awt.event.mouseAdapter; importar java.awt.event.mouseevent; importar java.net.url; importar javax.swing.imageicon; importar javax.swing.jframe; importar javax.swing.jpanel; importação com.sun.awt.awtutities; importar shen.panel.fadeout; classe pública movewindow estende mouseAdapter {private Point por último; quadro privado jframe; public MoveWindow (JFrame Frame) {this.frame = frame; } public void mousePressed (mouseevent e) {last = e.getLocationOnscreen (); } public void mouseReledEd (mouseevent e) {ponto de ponto = e.getLocationOnscreen (); Ponto fpoint = frame.getLocation (); frame.setLocation (fpoint.x + ponto.x - last.x, fpoint.y + point.y - last.y); último = ponto; }} 4
pacote shen; importar java.awt.graphics; importar java.awt.image; importar java.awt.event.mouseAdapter; importar java.awt.event.mouseevent; importar java.net.url; importar javax.swing.imageicon; importar javax.swing.jframe; importar javax.swing.jpanel; importação com.sun.awt.awtutities; importar com.wanju.blessing.showframe; Painel de classe pública estende JPanel {fundo privado de imagem; JFRame Frame = NULL; public jframe getFrame () {return frame; } public void SetFrame (JFrame Frame) {this.frame = frame; } Painel público (quadro jframe) {this.frame = frame; tente {// background = imageio.read (novo arquivo ("d: //workspace//maven//blessing//src//shen//window.png")); // background = imageio.read (novo arquivo ("d: //workspace//maven//blessing//src//shen//b.jpg")); Url url = painel.class.getResource ("c.jpg"); Icon imageicon = novo imageicon (URL); Antecedentes = icon.getImage (); // background = imageio.read (novo arquivo ("d: //workspace//maven//blessing//src//shen//b.jpg")); this.addmouselistener (new mouseAdapter () {@Override public void mouseclicked (mouseevent e) {super.mouseClicked (e); new fadeout (pain.this.frame) .start ();}}); } catch (Exceção e) {e.printStackTrace (); }} classe fadeout estende o 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 (Exceção ex) {ex.PrintStackTrace (); } wnd.setVisible (false); wnd.dispose (); new showframe (); }} Void PaintComponent protegido (gráficos g) {super.PaintComponent (g); G.Drawimage (Antecedentes, 0,0,666.666, NULL); }}5 效果图:
以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。