服务器之家

服务器之家 > 正文

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

时间:2021-04-25 13:18     来源/作者:瓜瓜东西

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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版给爱人表白的玫瑰花程序代码

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

原文链接:https://blog.csdn.net/cgwcgw_/article/details/19899169

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
返回顶部