欢迎来到天天文库
浏览记录
ID:34734853
大小:91.63 KB
页数:4页
时间:2019-03-10
《云大java实验9lab#9(陆歌浩)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、云南大学软件学院实验报告课程:Java程序设计实验学期:2012-2013学年第一学期任课教师:陆歌浩专业:软件工程学号:序号:姓名:成绩:实验9图形编程一、实验目的练习Java中图形编程概念的应用。二、实验内容Program1CreateanapplicationDisplayNamesthatdisplaysyournameineveryeven-numberedfontfromsize4to24. Makethecolorred.Youshouldcreate3classesnamed:·DrawNamesTest.java·NamesFram
2、e.java·NamesPanel.java实验代码:packageedu.ynu.lab9;importjava.awt.*;importjavax.swing.*;importjava.awt.font.*;importjava.awt.geom.*;publicclassDrawNamesTest{publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){NamesFrameframe=newNamesFrame();frame
3、.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}});}}4classNamesFrameextendsJFrame{publicNamesFrame(){setTitle("孙金文-2010120007");setSize(300,300);setLocation(400,250);NamesPanelpanel=newNamesPanel();add(panel);}}classNamesPanelextendsJComponent{publicvoi
4、dpaintComponent(Graphicsg){Graphics2Dg2=(Graphics2D)g;Stringmessage="SunJinwen";Fontf1=newFont("Serif",Font.BOLD,4);//设置字体g2.setPaint(Color.RED);//设置字体颜色intmessageY=30;intmessageX=50;for(floati=4;i<25;i+=2){Fontf=f1.deriveFont(i);//设置字体大小g2.setFont(f);g2.drawString(message,mess
5、ageX,messageY);FontRenderContextcontext=g2.getFontRenderContext();Rectangle2Dbounds=f.getStringBounds(message,context);messageY+=bounds.getHeight()+3;}}}运行截图:Program2CreateanapplicationShapesTestthatdisplaysvariousshapesinvariouscolors.4·alineinblackcolor·acircleingreencolor·a
6、rectangleinorangecolor Usethelecturenotesforaguide.Youshouldcreate3classesnamed:·ShapesTest.java·ShapesFrame.java·ShapesPanel.java实验代码:packageedu.ynu.lab9;importjava.awt.*;importjava.awt.geom.*;importjavax.swing.*;publicclassShapesTest{publicstaticvoidmain(String[]args){EventQu
7、eue.invokeLater(newRunnable(){publicvoidrun(){ShapesFrameframe=newShapesFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}});}}classShapesFrameextendsJFrame{publicShapesFrame(){setTitle("孙金文-20101120007");setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
8、//设置框架的大小setLocation(DEFAULT_WIDTH,DEFAULT_HEIGHT);//设
此文档下载收益归作者所有