1书写表白语句的フレーム(渐入功能)
パッケージcom.wanju.blessing; java.awt.colorをインポートします。 Import Java.awt.Container; java.awt.dimensionをインポートします。 java.awt.fontをインポートします。 java.awt.graphicsをインポートします。 java.awt.imageをインポートします。 java.awt.toolkitをインポートします。 java.awt.event.mouseadapterをインポートします。 java.awt.event.MouseEventをインポートします。 java.net.urlをインポートします。 javax.swing.imageiconをインポートします。 javax.swing.jframeをインポートします。 javax.swing.jpanelをインポートします。 Import Shen.Panel; com.sun.awt.awtutilitiesをインポートします。 Public Class Showframeは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);コンテナコンテナ= this.getContentPane(); // awtutilities.setWindowopaque(これ、true); awtutilities.setWindowopacity(this、0.01f); container.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 extends jpanel {private image background; JFrameフレーム; Public MyPanel(最終jFrameフレーム){this.frame = frame; try {url url = panel.class.getResource( "a.jpg"); ImageIcon Icon = new ImageIcon(URL); background = icon.getimage(); // background = imageio.read(new file( "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); disose(); } catch(Exception e){e.printstacktrace(); }}保護されたvoid paintComponent(Graphics G){super.paintComponent(g); G.drawimage(背景、0,0,666,666、null); g.setcolor(color.red); g.setFont(new Font( ""、font.bold、15)); G.DrawString( "祝愿宝儿永远幸福的像花儿一样"、60、280); }} class Fadeoutはスレッドを拡張します{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玫瑰花フレーム
パッケージシェン; java.awt.eventqueueをインポートします。 javax.swing.jframeをインポートします。 com.sun.awt.awtutilitiesをインポートします。パブリッククラスフレームはjframe {private static final long serialversionuid = 7517576070147366983l; public frame(){settitle( "png透明窗体"); setDefaultCloseoperation(jframe.exit_on_close); setundecorated(true); SetSize(666、666); setLocationRelativeto(null); awtutilities.setWindowopaque(これ、false); setContentPane(新しいパネル(この)); addMousElistener(new MoveWindow(This)); } public static void main(string [] args){eventqueue.invokelater(new runnable(){@override public void run(){new frame()。setVisible(true);}}); }}3
パッケージシェン; java.awt.graphicsをインポートします。 java.awt.imageをインポートします。 java.awt.pointをインポートします。 java.awt.event.mouseadapterをインポートします。 java.awt.event.MouseEventをインポートします。 java.net.urlをインポートします。 javax.swing.imageiconをインポートします。 javax.swing.jframeをインポートします。 javax.swing.jpanelをインポートします。 com.sun.awt.awtutilitiesをインポートします。 import shen.panel.fadeout; Public Class MoveWindowはMouseadapterを拡張します{private Point last;プライベートJFrameフレーム。 public MoveWindow(JFrame Frame){this.frame = frame; } public void mousepressed(mousevent e){last = e.getLocationOnscreen(); } public void mouseReleased(mousevent e){point point = e.getLocationOnscreen();ポイントfpoint = frame.getLocation(); frame.setlocation(fpoint.x + point.x -last.x、fpoint.y + point.y -last.y); last = point; }} 4
パッケージシェン; java.awt.graphicsをインポートします。 java.awt.imageをインポートします。 java.awt.event.mouseadapterをインポートします。 java.awt.event.MouseEventをインポートします。 java.net.urlをインポートします。 javax.swing.imageiconをインポートします。 javax.swing.jframeをインポートします。 javax.swing.jpanelをインポートします。 com.sun.awt.awtutilitiesをインポートします。 com.wanju.blessing.showframeをインポートします。パブリッククラスパネルはjpanel {プライベート画像の背景; jframe frame = null; public jframe getFrame(){return frame; } public void setframe(jframe frame){this.frame = frame; } publicパネル(jframeフレーム){this.frame = frame; try {// background = imageio.read(new file( "d://workspace//maven//blessing//src//shen//window.png"); // background = imageio.read(new file( "d://workspace//maven//blessing//src//shen//b.jpg")); url url = panel.class.getResource( "c.jpg"); ImageIcon Icon = new ImageIcon(URL); background = icon.getimage(); // background = imageio.read(new file( "d://workspace//maven//blessing//src//shen//b.jpg")); this.addmouseListener(new MouseAdapter(){@Override public void mouseClicked(mouseEvent e){super.MouseClicked(e); new Fadeout(Panel.This.Frame).Start();}}); } catch(Exception e){e.printstacktrace(); }} class Fadeoutはスレッドを拡張します{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();新しいshowframe(); }}保護されたvoid paintComponent(Graphics G){super.paintComponent(g); G.drawimage(背景、0,0,666,666、null); }}5效果图:
以上就是本文的全部内容、希望对大家的学习有所帮助、也希望大家多多支持武林网。