Java实验6Word版

上传人:日度 文档编号:215065178 上传时间:2021-11-24 格式:DOC 页数:5 大小:41.50KB
返回 下载 相关 举报
Java实验6Word版_第1页
第1页 / 共5页
Java实验6Word版_第2页
第2页 / 共5页
Java实验6Word版_第3页
第3页 / 共5页
Java实验6Word版_第4页
第4页 / 共5页
Java实验6Word版_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《Java实验6Word版》由会员分享,可在线阅读,更多相关《Java实验6Word版(5页珍藏版)》请在金锄头文库上搜索。

1、实验六一、 实验内容: 编写一个程序,使用GeneralPath类绘制一个彩色的五角星。 在程序中加入颜色渐变效果,使用GradientPaint(float x1,float y1,Color color1,float x2,float y2,Color color1,boolean cyclic)发方法达到完成这个功能。 程序中加入字体控制。 绘制两个3D矩形,一个是凸出效果,另一个是凹下效果。二、 实验结果:三、 实验代码:import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import javax.swing

2、.*; public class Star extends JFramepublic Star()super(彩色五角星);setSize(800,600);setVisible(true); public void paint(Graphics g) super.paint(g); Graphics2D g2d=(Graphics2D)g; g2d.setPaint(Color.red); g2d.fillRect(100,10,400,300); g2d.setPaint(Color.black); g2d.fillRect(100,10,10,500); g2d.setPaint(Col

3、or.yellow); float x=new float3; float y=new float3; x0=200; y0=30; x1=(560/3); y1=70; x2=(640/3); y2=70; GeneralPath tour=new GeneralPath(); tour.moveTo(x0,y0); for(int i=0;ix.length;i+) tour.lineTo(xi,yi); g2d.fill(tour); g2d.setPaint(Color.blue); float x1=new float3; float y1=new float3; x10=140;

4、y10=70; x11=(560/3); y11=70; x12=175; y12=105; GeneralPath tour1=new GeneralPath(); tour1.moveTo(x10,y10); for(int i=0;ix1.length;i+) tour1.lineTo(x1i,y1i); g2d.fill(tour1); g2d.setPaint(Color.green); float x2=new float3; float y2=new float3; x20=150; y20=180; x21=200; y21=130; x22=175; y22=105; Gen

5、eralPath tour2=new GeneralPath(); tour2.moveTo(x20,y20); for(int i=0;ix2.length;i+) tour2.lineTo(x2i,y2i); g2d.fill(tour2); g2d.setPaint(Color.orange); float x3=new float3; float y3=new float3; x30=250; y30=180; x31=200; y31=130; x32=225; y32=105; GeneralPath tour3=new GeneralPath(); tour3.moveTo(x3

6、0,y30); for(int i=0;ix3.length;i+) tour3.lineTo(x3i,y3i); g2d.fill(tour3); g2d.setPaint(Color.cyan); float x4=new float3; float y4=new float3; x40=260; y40=70; x41=(640/3); y41=70; x42=225; y42=105; GeneralPath tour4=new GeneralPath(); tour4.moveTo(x40,y40); for(int i=0;ix4.length;i+) tour4.lineTo(x

7、4i,y4i); g2d.fill(tour4); g2d.setPaint(Color.magenta); float x5=new float5; float y5=new float5; x50=(560/3); y50=70; x51=(640/3); y51=70; x52=225; y52=105; x53=200; y53=130; x54=175; y54=105; GeneralPath tour5=new GeneralPath(); tour5.moveTo(x50,y50); for(int i=0;ix5.length;i+) tour5.lineTo(x5i,y5i

8、); g2d.fill(tour5); g.setColor(new Color(255,0,255); g.setFont(new Font(楷体,Font.BOLD,24); g.drawString(彩色的五角星,300,400); g2d.setPaint(new GradientPaint(10,10,Color.blue,25,30,Color.green,true); g2d.setStroke(new BasicStroke(20.0f); g2d.draw(new Rectangle2D.Double(350,450,65,110); g.setColor(Color.ora

9、nge); g.fill3DRect(500,500,60,50,false); g.setColor(Color.pink); g.fill3DRect(600,500,60,50,true); public static void main(String args) Star application=new Star(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 四、 体会小结:这次实验,我是第一次在程序中绘制图形,感觉还是挺有趣的。以前编的程序还是注重解题算法,而没有重视界面的美化。通过这次实验,我也掌握了一些绘图技巧和关于绘图编程的思路。众所周知,算法是体现程序优劣的很重要的标准,然后,算法是体现在代码的字里行间的,是需要慢慢使用软件后,才会让用感觉到这款程序好不好(其实就是这款软件的算法好不好),但是,现在学了这章Java后,我知道了,在用好的算法进行编软件时,我们也要学会用图形化界面吸引用户,因为友好的图形化界面,是在第一时间最能打动用户的 (注:可编辑下载,若有不当之处,请指正,谢谢!)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号