資源描述:
《云大java實(shí)驗(yàn)9lab#9(陸歌浩)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、云南大學(xué)軟件學(xué)院實(shí)驗(yàn)報(bào)告課程:Java程序設(shè)計(jì)實(shí)驗(yàn)學(xué)期:2012-2013學(xué)年第一學(xué)期任課教師:陸歌浩專業(yè):軟件工程學(xué)號:序號:姓名:成績:實(shí)驗(yàn)9圖形編程一、實(shí)驗(yàn)?zāi)康木毩?xí)Java中圖形編程概念的應(yīng)用。二、實(shí)驗(yàn)內(nèi)容Program1CreateanapplicationDisplayNamesthatdisplaysyournameineveryeven-numberedfontfromsize4to24.?Makethecolorred.Youshouldcreate3classesnamed:·DrawNamesTest.java·NamesFram
2、e.java·NamesPanel.java實(shí)驗(yàn)代碼: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);//設(shè)置字體g2.setPaint(Color.RED);//設(shè)置字體顏色intmessageY=30;intmessageX=50;for(floati=4;i<25;i+=2){Fontf=f1.deriveFont(i);//設(shè)置字體大小g2.setFont(f);g2.drawString(message,mess
5、ageX,messageY);FontRenderContextcontext=g2.getFontRenderContext();Rectangle2Dbounds=f.getStringBounds(message,context);messageY+=bounds.getHeight()+3;}}}運(yùn)行截圖:Program2CreateanapplicationShapesTestthatdisplaysvariousshapesinvariouscolors.4·alineinblackcolor·acircleingreencolor·a
6、rectangleinorangecolor?Usethelecturenotesforaguide.Youshouldcreate3classesnamed:·ShapesTest.java·ShapesFrame.java·ShapesPanel.java實(shí)驗(yàn)代碼: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、//設(shè)置框架的大小setLocation(DEFAULT_WIDTH,DEFAULT_HEIGHT);//設(shè)