page contents

eclipse表白代码——给爱人表白的玫瑰花程序

这篇文章主要讲解了Java版给爱人表白的玫瑰花程序代码,具有很好的参考价值,希望对大家有所帮助,一起跟随六星小编过来看看吧

attachments-2021-12-lbgA0Vi161c27ff3b4494.png

这篇文章主要讲解了Java版给爱人表白的玫瑰花程序代码,具有很好的参考价值,希望对大家有所帮助,一起跟随六星小编过来看看吧

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(600500);
 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(this0.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("祝愿宝儿永远幸福的像花儿一样"60280);
 }
}
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 效果图:

attachments-2021-12-1Ukyjs0f61c27fb14a452.png
attachments-2021-12-C46eSWvq61c27fb866f49.png
更多相关技术内容咨询欢迎前往并持续关注六星社区了解详情。

如果你想用Python开辟副业赚钱,但不熟悉爬虫与反爬虫技术,没有接单途径,也缺乏兼职经验
关注下方微信公众号:Python编程学习圈,获取价值999元全套Python入门到进阶的学习资料以及教程,还有Python技术交流群一起交流学习哦。
attachments-2022-06-TQ0MoXXN62b26c239655b.jpeg

  • 发表于 2021-12-22 09:32
  • 阅读 ( 4232 )
  • 分类:行业资讯

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
轩辕小不懂
轩辕小不懂

2403 篇文章

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. 小柒 1474 文章
  3. Pack 1135 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章