我今天有空,请告诉我哄妹妹的case先生。 我需要做一个心形。 根据心形的位置和长度,截断生成的字符串并输出到所需位置。 最终可以在画面上表达出满满的爱之心。 不说废话,直接上传到源代码看效果~
打包滴滴涕;
import java.awt.*;
import javax.swing.JFrame;
publicclasscardioidextendsjframe {
//取得画面尺寸
私密静态金融int width=500;
私有身份识别=500;
privatestaticintwindow _ width=toolkit.getdefaulttoolkit ().getScreenSize ).width;
privatestaticintwindow _ height=toolkit.getdefaulttoolkit ().getScreenSize ).height;
公共卡标识
super(Iloveyou ); //设置窗口标题
this.setbackground(color.black );
this.set location ((window _ width-width )/2,) WINDOW_HEIGHT-HEIGHT )/2 ); //设定窗口的位置
this.setsize(Width,HEIGHT ); //设定窗口大小
this.set layout (获取布局) ); //设置窗口布局
this.setvisible(true; //可以看到设定窗口
this.setdefaultcloseoperation (dispose _ on _ close; //设置窗口的默认关闭方式
}
公共语音绘制(图形) {
双精度x,y,r; //横纵坐标及半径
image image=this.create image (width,HEIGHT );
Graphics pic=image.getGraphics (;
for(intI=-2; i 90; I ) {
for(intj=-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 ); //生成图像
}
}
publicstaticvoidmain (字符串[ ] args ) {
新cardio id (;
}
}
效果如下。
以上是这篇文章的所有内容。 希望这篇文章的内容对大家的学习和工作有一定的参考学习价值。 如果有疑问的话,请在评论中交流。 感谢您对编剧的支持。