欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java版给爱人表白的玫瑰花程序代码

程序员文章站 2023-12-15 09:25:34
1 书写表白语句的frame(渐入功能) package com.wanju.blessing; import java.awt.color; impor...

1 书写表白语句的frame(渐入功能)

package com.wanju.blessing; 
import java.awt.color; 
import java.awt.container; 
import java.awt.dimension; 
import java.awt.font; 
import java.awt.graphics; 
import java.awt.image; 
import java.awt.toolkit; 
import java.awt.event.mouseadapter; 
import java.awt.event.mouseevent; 
import java.net.url; 
import javax.swing.imageicon; 
import javax.swing.jframe; 
import javax.swing.jpanel; 
import shen.panel; 
import com.sun.awt.awtutilities; 
public class showframe extends 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); 
 container container = this.getcontentpane(); 
// awtutilities.setwindowopaque(this, 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 frame; 
 public mypanel(final jframe frame){ 
 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); 
   frame.dispose(); 
  } 
  }); 
 } catch (exception e) { 
  e.printstacktrace(); 
 } 
 } 
 protected void paintcomponent(graphics g) { 
 super.paintcomponent(g); 
 g.drawimage(background,0,0,666,666,null); 
 g.setcolor(color.red); 
 g.setfont(new font("", font.bold, 15)); 
 g.drawstring("祝愿宝儿永远幸福的像花儿一样", 60, 280); 
 } 
} 
class fadeout extends 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 玫瑰花frame

package shen; 
 
import java.awt.eventqueue; 
import javax.swing.jframe; 
 
 
import com.sun.awt.awtutilities; 
 
public class frame extends 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(this, false); 
 setcontentpane(new panel(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; 
import java.awt.point; 
import java.awt.event.mouseadapter; 
import java.awt.event.mouseevent; 
import java.net.url; 
 
import javax.swing.imageicon; 
import javax.swing.jframe; 
import javax.swing.jpanel; 
 
import com.sun.awt.awtutilities; 
 
import shen.panel.fadeout; 
 
public class movewindow extends mouseadapter { 
 
 private point last; 
 private jframe frame; 
 
 public movewindow(jframe frame) { 
 this.frame = frame; 
 } 
 
 public void mousepressed(mouseevent e) { 
 last = e.getlocationonscreen(); 
 } 
 
 public void mousereleased(mouseevent e) { 
 point point = e.getlocationonscreen(); 
 point fpoint = frame.getlocation(); 
 frame.setlocation(fpoint.x + point.x - last.x, fpoint.y + point.y 
  - last.y); 
 last = point; 
 } 
 
} 

4

package shen; 
 
import java.awt.graphics; 
import java.awt.image; 
import java.awt.event.mouseadapter; 
import java.awt.event.mouseevent; 
import 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; 
 
public class panel extends jpanel{ 
 
 private image background; 
 jframe frame = null; 
 public jframe getframe() { 
 return frame; 
 } 
 
 public void setframe(jframe frame) { 
 this.frame = frame; 
 } 
 
 public panel(jframe frame){ 
 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 extends 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(); 
  new showframe(); 
 } 
 } 
 
 protected void paintcomponent(graphics g) { 
 super.paintcomponent(g); 
 g.drawimage(background,0,0,666,666,null); 
 } 
} 

5 效果图:

Java版给爱人表白的玫瑰花程序代码

Java版给爱人表白的玫瑰花程序代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: