版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Java-2實(shí)用教程實(shí)驗(yàn)指導(dǎo)模版代碼Java-2實(shí)用教程實(shí)驗(yàn)指導(dǎo)模版代碼Java-2實(shí)用教程實(shí)驗(yàn)指導(dǎo)模版代碼Java-2實(shí)用教程實(shí)驗(yàn)指導(dǎo)模版代碼編制僅供參考審核批準(zhǔn)生效日期地址:電話:傳真:郵編:TOC\o"1-3"\h\z上機(jī)實(shí)踐1初識(shí)Java 3實(shí)驗(yàn)1一個(gè)簡(jiǎn)單的應(yīng)用程序 3實(shí)驗(yàn)2一個(gè)簡(jiǎn)單的JavaApplet程序 3實(shí)驗(yàn)3聯(lián)合編譯 4上機(jī)實(shí)踐2基本數(shù)據(jù)類型與控制語(yǔ)句 6實(shí)驗(yàn)1輸出希臘字母表 6實(shí)驗(yàn)2回文數(shù) 6實(shí)驗(yàn)3猜數(shù)字游戲 9上機(jī)實(shí)踐3類與對(duì)象 10實(shí)驗(yàn)1三角形、梯形和圓形的類封裝 10實(shí)驗(yàn)2實(shí)例成員與類成員 13實(shí)驗(yàn)3使用package語(yǔ)句與import語(yǔ)句 14上機(jī)實(shí)踐4繼承與接口 17實(shí)驗(yàn)1繼承 17實(shí)驗(yàn)2上轉(zhuǎn)型對(duì)象 19實(shí)驗(yàn)3接口回調(diào) 20上機(jī)實(shí)踐5字符串、時(shí)間與數(shù)字 22實(shí)驗(yàn)1String類的常用方法 22實(shí)驗(yàn)2比較日期的大小 24實(shí)驗(yàn)3處理大整數(shù) 25上機(jī)實(shí)踐6圖形用戶界面設(shè)計(jì)(1) 27實(shí)驗(yàn)2信號(hào)燈 28實(shí)驗(yàn)3布局與日歷 31上機(jī)實(shí)踐7圖形用戶界面設(shè)計(jì)(2) 35實(shí)驗(yàn)2字體對(duì)話框 36實(shí)驗(yàn)3華容道游戲 39上機(jī)實(shí)踐8多線程 47實(shí)驗(yàn)1線程的4種狀態(tài) 47實(shí)驗(yàn)2線程之間共享數(shù)據(jù) 49實(shí)驗(yàn)3掛起、恢復(fù)和終止線程 51上機(jī)實(shí)踐9輸入輸出流 55實(shí)驗(yàn)1文件加密 55實(shí)驗(yàn)2給文件的內(nèi)容添加行號(hào) 56實(shí)驗(yàn)3使用RandomAcessFile類處理文件 58實(shí)驗(yàn)4對(duì)象的寫入與讀取 60上機(jī)實(shí)踐10Java中的網(wǎng)絡(luò)編程 61實(shí)驗(yàn)1讀取服務(wù)器端文件 61實(shí)驗(yàn)2使用套接字讀取服務(wù)器端對(duì)象 63實(shí)驗(yàn)3基于UDP的圖像傳輸 67上機(jī)實(shí)踐11javaSwing 72實(shí)驗(yàn)1JLayeredPane分層窗格 72實(shí)驗(yàn)2進(jìn)度條 73實(shí)驗(yàn)3使用表格顯示日歷 75實(shí)驗(yàn)4多文檔界面(MDI) 80上機(jī)實(shí)踐12數(shù)據(jù)結(jié)構(gòu) 84實(shí)驗(yàn)1隨機(jī)布雷 84實(shí)驗(yàn)2使用TreeSet排序 86
上機(jī)實(shí)踐1初識(shí)Java實(shí)驗(yàn)1一個(gè)簡(jiǎn)單的應(yīng)用程序程序模板publicclassHello{publicstaticvoidmain(Stringargs[]){【代碼1】;import.*;publicclassFirstAppletextendsApplet{publicvoidpaint(Graphicsg){;【代碼1】;classSunRise{publicstaticvoidmain(Stringargs[]){SquareEquationequation=newSquareEquation(4,5,1);();(-3,4,5);();}}
上機(jī)實(shí)踐4繼承與接口實(shí)驗(yàn)1繼承程序模板classPeople{protecteddoubleweight,height;publicvoidspeakHello(){"yayawawa");}publicvoidaverageHeight(){height=173;"averageheight:"+height);}publicvoidaverageWeight(){weight=70;"averageweight:"+weight);}}classChinaPeopleextendsPeople{【代碼1】;importDateExample{publicstaticvoidmain(Stringargs[]){Stringstr=("輸入第一個(gè)日期的年份:");intyearOne=(str);str=("輸入該年的月份:");intmonthOne=(str);str=("輸入該月份的日期:");intdayOne=(str);str=("輸入第二個(gè)日期的年份:");intyearTwo=(str);str=("輸入該年的月份:");intmonthTwo=(str);str=("輸入該月份的日期:");intdayTwo=(str);Calendarcalendar=【代碼1】;classBigIntegerExample{publicstaticvoidmain(Stringargs[]){BigIntegern1=newBigInteger("654321"),n2=newBigInteger("456789"),result=null;"n1的二進(jìn)制表示:"+(2));"n2的八進(jìn)制表示:"+(8));result=【代碼1】;import.*;publicclassGuessExampleextendsAppletimplementsActionListener{intnumber;TextFieldinputNumber;LabelfeedBack;ButtonnuttonGetNumber,buttonEnter;publicvoidinit(){nuttonGetNumber=newButton("得到一個(gè)隨機(jī)數(shù)");feedBack=newLabel("無(wú)反饋信息",;;inputNumber=newTextField("0",5);buttonEnter=newButton("確定");【代碼1】;import.*;importclassSignalExampleextendsAppletimplementsActionListener{ButtonbuttonRed,buttonGreen,buttonYellow;SignalCanvassignal;publicvoidinit(){buttonRed=【代碼1】;import.*;import.*;publicclassBoyextendsAppletimplementsActionListener{Labela[]=newLabel[42];ButtontitleName[]=newButton[7];Stringname[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};ButtonnextMonth,previousMonth;intyear=2005,month=1;CalendarBeancalendar;LabelshowMessage=newLabel("",;publicvoidinit(){【代碼1】etText(day[i]);}nextMonth=newButton("下月");previousMonth=newButton("上月");(this);(this);PanelpNorth=newPanel(),pSouth=newPanel();(previousMonth);(nextMonth);(showMessage);("日歷:"+()+"年"+()+"月");ScrollPanescrollPane=newScrollPane();(pCenter);【代碼5】etText(day[i]);}}elseif()==previousMonth){month=month-1;if(month<1)month=12;(month);Stringday[]=();for(inti=0;i<42;i++){a[i].setText(day[i]);}}("日歷:"+()+"年"+()+"月");}}classCalendarBean{Stringday[];intyear=2005,month=0;publicvoidsetYear(intyear){=year;}publicintgetYear(){returnyear;}publicvoidsetMonth(intmonth){=month;}publicintgetMonth(){returnmonth;}publicString[]getCalendar(){Stringa[]=newString[42];et(year,month-1,1);int星期幾=日歷.get-1;intday=0;if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){day=31;}if(month==4||month==6||month==9||month==11){day=30;}if(month==2){if(((year%4==0)&&(year%100!=0))||(year%400==0)){day=29;}else{day=28;}}for(inti=星期幾,n=1;i<星期幾+day;i++){a[i]=(n);n++;}returna;}}
上機(jī)實(shí)踐7圖形用戶界面設(shè)計(jì)(2)程序模板import.*;importMyFrameextendsFrameimplementsActionListener{MenuBarbar=null;Menumenu=null;MenuItemitemRed,itemGreen;MyFrame(Strings){super(s);【代碼1】;importFontDialogextendsDialogimplementsItemListener,ActionListener{Choicelist;JTextAreatext;Fontfont;Buttonyes,cancel;Componentcom;FontDialog(Framef,Stringname,Componentcom){super(f,name);=com;【代碼1】;importclassMoveExample{publicstaticvoidmain(Stringargs[]){newHua_Rong_Road();}}classPersonextendsButtonimplementsFocusListener{intnumber;Colorc;Person(intnumber,Strings){super(s);=number;setFont(newFont("宋體",,14));setBackground;【代碼1】etBounds(104,54,100,100);person[1].setBounds(104,154,100,50);person[2].setBounds(54,154,50,100);person[3].setBounds(204,154,50,100);person[4].setBounds(54,54,50,100);person[5].setBounds(204,54,50,100);person[6].setBounds(54,254,50,50);person[7].setBounds(204,254,50,50);person[8].setBounds(104,204,50,50);person[9].setBounds(154,204,50,50);【代碼6】idth;inth=().height;if(y>h/2){goDown(man);}if(y<h/2){goUp(man);}if(x<w/2){goLeft(man);}if(x>w/2){goRight(man);}}publicvoidmouseReleased(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseClicked(MouseEvente){}publicvoidgoDown(Personman){booleanmove=true;RectanglemanRect=();intx=().x;inty=().y;y=y+50;(x,y);RectanglebelowRect=();for(inti=0;i<10;i++){RectanglepersonRect=person[i].getBounds();if((personRect))&&!=i)){move=false;}}if(belowRect)){move=false;}if(move==true){(x,y);}}publicvoidgoUp(Personman){booleanmove=true;RectanglemanRect=();intx=().x;inty=().y;y=y-50;(x,y);RectangleaboveRect=();for(inti=0;i<10;i++){RectanglepersonRect=person[i].getBounds();if((personRect))&&!=i)){move=false;}}if(aboveRect)){move=false;}if(move==true){(x,y);}}publicvoidgoLeft(Personman){booleanmove=true;RectanglemanRect=();intx=().x;inty=().y;x=x-50;(x,y);RectangleleftRect=();for(inti=0;i<10;i++){RectanglepersonRect=person[i].getBounds();if((personRect))&&!=i)){move=false;}}if(leftRect)){move=false;}if(move==true){(x,y);}}publicvoidgoRight(Personman){booleanmove=true;RectanglemanRect=();intx=().x;inty=().y;x=x+50;(x,y);RectanglerightRect=();for(inti=0;i<10;i++){RectanglepersonRect=person[i].getBounds();if((personRect))&&!=i)){move=false;}}if(rightRect)){move=false;}if(move==true){(x,y);}}publicvoidactionPerformed(ActionEvente){removeAll();init();validate();repaint();}}
上機(jī)實(shí)踐8多線程實(shí)驗(yàn)1線程的4種狀態(tài)程序模板classTortoiseextendsThread{intsleepTime=0,liveLength=0;Tortoise(intsleepTime,Stringname,intliveLength){=sleepTime;=liveLength;setName(name);}publicvoidrun(){while(true){liveLength--;"@");try{【代碼1】;importWinextendsFrameimplementsRunnable,ActionListener{ThreadmoveOrStop;Buttonstart,hang,resume,die;LabelmoveLabel;booleanmove=false,dead=false;Win(){【代碼1】;inty=().y;y=y+2;if(y>=200)y=10;(x,y);try{(200);}catch(InterruptedExceptione2){}if(dead==true){【代碼5】;publicclassSecretExample{publicstaticvoidmain(Stringargs[]){FilefileOne=newFile(""),fileTwo=newFile("");charb[]=newchar[100];try{FileReaderin=【代碼1】;publicclassReadExample{publicstaticvoidmain(Stringargs[]){Filefile=newFile("c:/1000","");FiletempFile=newFile("");try{FileReaderinOne=【代碼1】;publicclassRandomExample{publicstaticvoidmain(Stringargs[]);import.*;publicclassObjectExample{publicstaticvoidmain(Stringargs[]){Calendarcalendar1=();;import.*;import.*;import.*;publicclassReadFileextendsAppletimplementsActionListener,Runnable{Filefile;Choicechoice;TextAreatext;Threadthread;Stringitem=null;Buttonbutton;URLurl;publicvoidinit(){choice=newChoice();thread=newThread(this);intN=(getParameter("總數(shù)"));for(inti=1;i<=N;i++){(getParameter(i)));}button=newButton("開始讀取");text=newTextArea(12,40);(this);add(choice);add(button);add(text);}publicvoidactionPerformed(ActionEvente){(null);item=();item=();if(!())){thread=newThread(this);}try{();}catch(Exceptionexp){}}publicvoidrun(){try{url=newURL(getCodeBase(),item);InputStreamin=【代碼1】;import.*;import.*;importClientextendsFrameimplementsRunnable,ActionListener{Buttonconnection;Socketsocket=null;ObjectInputStreamin=null;ObjectOutputStreamout=null;Threadthread;publicClient(){socket=newSocket();connection=newButton("連接服務(wù)器,讀取文本區(qū)對(duì)象");add(connection,;(this);thread=newThread(this);setBounds(100,100,360,310);setVisible(true);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){(0);}});}publicvoidrun(){while(true){try{TextAreatext=(TextArea)();add(text,;validate();}catch(Exceptione){break;}}}publicvoidactionPerformed(ActionEvente){if()==connection){try{if()){}else{InetAddressaddress=("");InetSocketAddresssocketAddress=【代碼1】;import.*;import.*;import.*;publicclassServer{publicstaticvoidmain(Stringargs[]){ServerSocketserver=null;ServerThreadthread;Socketyou=null;while(true){try{server=【代碼1】tart();;import.*;import.*;classImageCanvasextendsCanvas{Imageimage=null;publicImageCanvas(){setSize(200,200);}publicvoidpaint(Graphicsg){if(image!=null)(image,0,0,getSize().width,getSize().height,this);}publicvoidsetImage(Imageimage){=image;}}classClientextendsFrameimplementsRunnable,ActionListener{Buttonb=newButton("獲取圖像");ImageCanvascanvas;Client(){super("Iamaclient");setSize(320,200);setVisible(true);(this);add(b,;canvas=newImageCanvas();add(canvas,;Threadthread=newThread(this);validate();addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){(0);}});();}publicvoidactionPerformed(ActionEventevent)rim().getBytes();try{InetAddressaddress=("");DatagramPacketdata=【代碼1】;import.*;publicclassServer{publicstaticvoidmain(Stringargs[]){DatagramPacketpack=null;DatagramSocketmailReceive=null;ServerThreadthread;byteb[]=newbyte[8192];InetAddressaddress=null;pack=newDatagramPacket(b,;while(true){try{mailReceive=【代碼1】tart();}else{continue;}}}}classServerThreadextendsThread{InetAddressaddress;DataOutputStreamout=null;DataInputStreamin=null;Strings=null;ServerThread(InetAddressaddress){=address;}publicvoidrun(){FileInputStreamin;byteb[]=newbyte[8192];try{in=newFileInputStream("");intn=-1;while((n=(b))!=-1){DatagramPacketdata=【代碼3】etBytes();DatagramPacketdata=【代碼6】;import.*;classLayerExample{publicstaticvoidmain(Stringargs[]){JFramewin=newJFrame("窗體");(100,100,300,300);(true);JButtonb1=newJButton("我在DEFAULT_LAYER"),b2=newJButton("我在PALETTE_LAYER"),b3=newJButton("我在MODAL_LAYER"),b4=newJButton("我在POPUP_LAYER"),b5=newJButton("我在DRAG_LAYER");ContainercontenetPane=();JLayeredPanepane=【代碼1】;import.*;importclassBarExample{publicstaticvoidmain(Stringargs[]){BarWinwin=newBarWin();}}classBarWinextendsJFrameimplementsRunnable{JProgressBarpbar1,pbar2;Threadthread1,thread2;JTextFieldtext1,text2;BarWin(){pbar1=【代碼1】;import.*;import.*;importclassCalendarExample{publicstaticvoidmain(Stringargs[]){newGoodWindow();}}classGoodWindowextendsJFrameimplementsItemListener{JComboBoxlist=null;CalenderPanecalenderPane=null;Containercon=null;GoodWindow(){list=【代碼1】/創(chuàng)建一個(gè)下拉列表,該列表不含有任何選項(xiàng)。for(inti=2000;i<=2010;i++){Stringtemp=""+i;【代碼2】et(year,month-1,1);int星期幾=日歷.get-1;intday=0;if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){day=31;}if(month==4||month==6||month==9||month==11){day=30;}if(month==2){if(((year%4==0)&&(year%100!=0))||(year%400==0)){day=29;}else{day=28;}}for(inti=星期幾,n=1;i<星期幾+day;i++){a[i]=(n);n++;}returna;}}實(shí)驗(yàn)4多文檔界面(MDI)程序模板import.*;import.*;importMyInternalFrameextendsJInternalFrame{JTextAreatext;MyInternalFrame(Stringtitle){super(title,true,true,true,true);text=newJTextArea();Containercon=getContentPane();(newJScrollPane(text),;setDefaultCloseOperation;addInternalFrameListener(newInternalFrameAdapter(){publicvoidinternalFrameActivated(InternalFrameEvente){setLayer;}publicvoidinternalFrameDeactivated(InternalFrameEvente){setLayer;}});}publicJTextAreagetJTextArea(){returntext;}}classMywindowextendsJFrameimplementsActionListener{JDesktopPanedesk;;classBlock{Stringname;booleanboo=false;publicvoidsetNam
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年稅務(wù)會(huì)計(jì)咨詢合同
- 銀行網(wǎng)點(diǎn)租賃合同模板
- 空氣凈化設(shè)備租賃協(xié)議樣本
- 排水管道管涵施工合同
- 超市收銀區(qū)地磚鋪裝項(xiàng)目協(xié)議
- 醫(yī)院防雷施工合同
- 商場(chǎng)衛(wèi)生清潔工招聘合同
- 未婚夫婚前房產(chǎn)協(xié)議
- 養(yǎng)老院租賃協(xié)議
- 通信工程商品混凝土施工協(xié)議
- 華北水利水電大學(xué)《自然語(yǔ)言處理課程設(shè)計(jì)》2023-2024學(xué)年第一學(xué)期期末試卷
- 國(guó)家開放大學(xué)《宣傳工作實(shí)務(wù)》專題測(cè)驗(yàn)1-12參考答案
- 2024年初級(jí)電焊工理論考試復(fù)習(xí)題庫(kù)(含答案)
- 2024年資助政策主題班會(huì)課件
- 2024年度人工智能AI技術(shù)服務(wù)合同3篇
- 江蘇省2025屆高三第一次模擬考試英語(yǔ)試卷含解析
- 教研組匯報(bào)課件
- 貴州省貴陽(yáng)市2023-2024學(xué)年高一上學(xué)期語(yǔ)文期末考試試卷(含答案)
- 化學(xué)必修一人教版知識(shí)點(diǎn)總結(jié)(超全)
- 肺部感染性疾病支氣管肺泡灌洗病原體檢測(cè)中國(guó)專家共識(shí)(2017年)
- 2024年秋季新人教版道德與法治七年級(jí)上冊(cè)全冊(cè)教案
評(píng)論
0/150
提交評(píng)論