您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

java实现七夕表白神器

2024/3/29 3:47:57发布6次查看
首先我们需要创建一个心形图案,然后按照心形图案的位置和长度,对所创建的字符串进行截断并在所需的位置上输出,最终能呈现在屏幕上满满的爱心。
(推荐教程:java入门教程)
实现代码:
package ddd; import java.awt.*; import javax.swing.jframe; public class cardioid extends jframe { //获取屏幕大小 private static final int width = 500; private static final int height = 500; private static int window_width = toolkit.getdefaulttoolkit().getscreensize().width; private static int window_height = toolkit.getdefaulttoolkit().getscreensize().height; public cardioid(){ super("i love you");//设置窗口标题 this.setbackground(color.black); this.setlocation((window_width-width)/2,(window_height-height)/2);//设置窗口位置 this.setsize(width, height);//设置窗口大小 this.setlayout(getlayout());//设置窗口布局 this.setvisible(true);//设置窗口可见 this.setdefaultcloseoperation(dispose_on_close);//设置窗口默认关闭方式 } public void paint(graphics g){ double x,y,r;//横纵坐标以及半径 image image = this.createimage(width, height); graphics pic = image.getgraphics(); for (int i = -2; i < 90; i++) { for (int j = -2; j < 90; j++) { r=math.pi/45+math.pi/45*i*(1-math.sin(math.pi/45*j))*18; x=r*math.cos(math.pi/45*j)*math.sin(math.pi/45*i)+width/2; y=-r*math.sin(math.pi/45*j)+height/3; pic.setcolor(color.magenta); pic.filloval((int)x, (int)y, 2, 2); } g.drawimage(image,0,0,this);//生成图片 } } public static void main(string[] args) { new cardioid(); }}
(学习视频推荐:java课程)
实现效果:
以上就是java实现七夕表白神器的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录