Java simulates WeChat call reminder

A few days ago on Douyin, I got a call from an octopus made by an older brother. It was very interesting, so I made one in Java.

The general process is as follows

  1. octopus call reminder
  2. text-reading
  3. Click the mouse effect, and then move the camera to the lower right corner of the computer
  4. Interspersed with this octopus recitation video (silent, the sound source is the text content)
  5. In the lower right corner, the call reminder of Brother Octopus pops up
  6. Incoming call countdown in the lower right corner + text 2 + text 3
  7. Play Octopus reciting Octopus reciting video + zhyg.wav sound

Let's do it! !

The renderings are as follows (I won't post a video, just watch it)

picture.png

picture.png

picture.png

picture.png

The code idea is as follows: It is made of JFrame of java.swing. Its native button is too ugly, so I thought of using Jlabel to put a picture and add a monitoring time to replace the function of the button.

//去掉窗口的装饰,title,最大化,最小,关闭按钮
this.setUndecorated(true);

The avatar of Brother Octopus was processed with PS, and the size was adjusted. The pixels of the picture are 100 x 100. The grid layout used will be automatically arranged to the right.

//章鱼哥头像
JLabel jLabel = new JLabel();
jLabel.setPreferredSize(new Dimension(100, 100));
//把图片放到resource下面,最好是用PS导出png透明格式
URL url = ImageIcon.class.getResource("/zhyg.png");
Icon icon = new ImageIcon(url);
jLabel.setIcon(icon);
jHeadPanel.add(jLabel);

The countdown in the middle is JTextField, set the font format, italics, 30 size, the answer button and hang up button are 40 x 40 pixels, and there are two transparent JLabels on it to occupy the space, otherwise the button will be displayed on it .

It is worth mentioning that a thread needs to be started when playing audio, otherwise it will block, which means that the code will be executed after the execution is completed, or the countdown will be executed after the playback is completed. Anyway, all kinds of strange problems.

//启动播放微信来电语音
PlayMp3 p = new PlayMp3();
new Thread(p).start();

When loading music, I tried the mp3 format, but it doesn't seem to work. I can use ffmpge or AE to process it, and export it in wav format. If you have the conditions at home, you can buy genuine software.

 File f = new File("wechat_call.wav");
            URI uri2 = f.toURI();
            URL url2 = uri2.toURL();
            //这里处理了一下加载路径的位置,要不然加载不到,这个URI和File加载的方式不一样
            String filename = url2.toString().replace("wechat_call.wav", "mail/src/main/resources/wechat_call.wav");
            URL url = URI.create(filename).toURL();
            AudioClip clip = Applet.newAudioClip(url);
//        控制音乐的播放与停止
            clip.play();
            Thread.sleep(10000);
            clip.stop();

Summary: At first, I thought that Java could not achieve this effect, but I didn't expect it to be quite similar, but the details were not dealt with. I probably realized it, and then I plan to add a to-do list and remind this when the countdown is over. If you have the opportunity, use Java Swing to draw WeChat pretend X, and then display this when you click to call, it will be more real, and it will be fake.

Guess you like

Origin juejin.im/post/7120584877879066660