九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOCX文檔下載  

Java程序設(shè)計(jì)教程 冶金工業(yè)出版社第9章pod

  • 資源ID:156539464       資源大?。?span id="24d9guoke414" class="font-tahoma">36.22KB        全文頁數(shù):20頁
  • 資源格式: DOCX        下載積分:20積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要20積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號,方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付方式: 微信支付   
驗(yàn)證碼:   換一換

 
賬號:
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請知曉。

Java程序設(shè)計(jì)教程 冶金工業(yè)出版社第9章pod

第9章多多線程與與Appplett //例程程9-11:Pii.jaava /*演示示采用多多線程技技術(shù)計(jì)算算圓周率率*/ publlic claass Pi{{ publlic staaticc vooid maiin(SStriing[[] aargss){ PiCaacullatoor pc = nnew PiCCacuulattor((); Threead t == neew TThreead((pc)); t.sttartt();; try{{ Threead..sleeep (1000000); //休眠眠,等待待可能出出現(xiàn)的異異常情況況 t.innterrruppt ();; }cattch((IntterrrupttedEExceeptiion e){{ e.prrinttStaackTTracce()); } } } classs PPiCaacullatoor iimpllemeentss Ruunnaablee{ privvatee douublee laatesstPiiEsttimaate;; publlic voiid rrun((){ try{{ Systtem..outt.prrintt (""Matth.PPI == "++ Matth.PPI + ""\t"" );; calPPi(00.0000011); Systtem..outt.prrinttln ("tthe lattestt PI = ""+thhis..lattesttPiEEstiimatte )); }cattch((IntterrrupttedEExceeptiion e){{ Systtem..outt.prrinttln(("Thhe cacculaatorr iss Innterrrupptedd.")); } } /***用于計(jì)計(jì)算圓周周率的方方法,aaccuuraccy為計(jì)計(jì)算精度度*/ privvatee voiid ccalPPi(ddoubble acccuraacy)) thhrowws IInteerruupteedExxcepptioon { thiss.laatesstPiiEsttimaate =0..0; longg itteraatioon = 00; int siggn == -11; //按給給定精度度計(jì)算圓圓周率 whille(MMathh.abbs ((Matth.PPI-tthiss.laatesstPiiEsttimaate))>acccurracyy){ if(TThreead..intterrruptted ())) throow nnew IntterrrupttedEExceeptiion((); iterratiion+++; signn = -siign;; thiss.laatesstPiiEsttimaate += (siign**4.00/(22*itteraatioon-11));; } } } //例程程9-22:SyynDeemo..javva /*演示示沒有進(jìn)進(jìn)行線程程同步所所帶來的的問題**/ publliccclasssSyynDeemo{{ publlic staaticc vooid maiin(SStriing[[] aargss){ Demoostrratoor ssharreDeemosstraatorr = neww Deemosstraatorr();; Threead t1 = nnew Thrreadd(shhareeDemmosttrattor,,"t11");; Threead t2 = nnew Thrreadd(shhareeDemmosttrattor,,"t22");; t1.sstarrt()); t2.sstarrt()); } } classs DDemoostrratoor iimpllemeentss Ruunnaablee{ privvatee innt ssharreDaata = 00; publlic voiid rrun((){ Threead t == Thhreaad.ccurrrenttThrreadd ()); for((intt i = 11; ii <== 5;; i+++){{ int coppy == shhareeDatta; try{{ Threead..sleeep ((iint))(Maath..ranndomm ())*10000))); }cattch((Exccepttionn e)){ e.prrinttStaackTTracce()); } Systtem..outt.prrinttln ("TThreead "+tt.geetNaame ()++": coppy=""+coopy +"\\tshhareeDatta=""+shhareeDatta);; sharreDaata+++; } } } //例程程9-33:DeeadLLockkDemmo.jjavaa publlic claass DeaadLoockDDemoo{ publlic staaticc vooid maiin(SStriing[[] aargss){ DemooObjjectt a = nnew DemmoObbjecct()); DemooObjjectt b = nnew DemmoObbjecct()); a.annothher = bb; b.annothher = aa; Threead t1 = nnew Thrreadd(a,,"t11");; Threead t2 = nnew Thrreadd(b,,"t22");; t1.sstarrt ((); t2.sstarrt ((); } } classs DDemooObjjectt immpleemennts Runnnabble{{ publlic DemmoObbjecct aanottherr = nulll; publlic voiid rrun((){ thiss.meethood ((); } publlic synnchrroniizedd vooid metthodd(){{ if(tthiss.annothher != nulll){{ try{{ Threead..sleeep (10000)); }cattch((Exccepttionn e)){ e.prrinttStaackTTracce()); } anottherr.meethood ((); //下面面的代碼碼段實(shí)際際上是執(zhí)執(zhí)行不到到的 Systtem..outt.prrinttln ("IIf yyou cann seee tthiss liine,,no deaadloock happpenned""); } } } //例程程9-44:ThrreeTThreeadDDemoo.jaava /*ThhreeeThrreaddDemmo.jjavaa*/ publlic claass ThrreeTThreeadDDemoo{ puubliic sstattic voiid mmainn(Sttrinng[]] arrgs)){ //創(chuàng)建建新線程程 CCusttomTThreead ct11 = neww CuustoomThhreaad(00); CCusttomTThreead ct22 = neww CuustoomThhreaad(11); ///啟動(dòng)新新線程 cct1..staart ();; cct2..staart ();; //輸出出maiin線程程信息 ffor((intt i = 00; ii < 5; i+++){ Sysstemm.ouut.pprinntlnn("mmainn thhreaad: "+ii); }} SSysttem..outt.prrinttln ("mmainn thhreaad hhas donne!""); } } classs CCusttomTThreead exttendds TThreead{{ innt iid; puubliic CCusttomTThreead((intt cuustoomThhreaadIDD){ tthiss.idd = cusstommThrreaddID;; } //重定定義子線線程的rrun(()方法 puubliic vvoidd ruun()){ //輸出出自定義義線程的的信息 ffor((intt i = 00; ii < 5; i+++){ Sysstemm.ouut.pprinntlnn (""CusstommThrreadd #""+ tthiss.idd +"": ""+i)); }} SSysttem..outt.prrinttln ("CCusttomTThreead #"++thiis.iid+"" haas ddonee!")); } } //例程程9-55:DiggitaalCllockk.jaava /*采用用多線程程技術(shù)演演示一個(gè)個(gè)簡單的的數(shù)字時(shí)時(shí)鐘*// impoort javva.aawt..eveent..*; impoort javva.aawt..*; impoort javvax..swiing..*; publlic claass DiggitaalCllockk exxtennds JFrramee{ pubblicc sttatiic vvoidd maain((Strringg[] arggs) { JFFramme fframme == neew DDigiitallCloock((); frramee.shhow((); } pubblicc DiigittalCClocck()){ tthiss.seetSiize((2000,1550);; tthiss.seetDeefauultCClosseOpperaatioon(JJFraame..EXIIT_OON_CCLOSSE);; ///數(shù)字時(shí)時(shí)鐘面板板 ffinaal CClocckPaane cp = nnew CloockPPanee();; //設(shè)置置按鈕狀狀態(tài)并注注冊事件件監(jiān)聽者者 ffinaal JJButttonn sttartt = neww JBButtton(("sttartt");; ffinaal JJButttonn sttop = nnew JBuuttoon(""stoop")); sstopp.seetEnnablled((fallse)); sstarrt.aaddAActiionLListteneer(nnew ActtionnLisstenner((){ puubliic vvoidd acctioonPeerfoormeed(AActiionEEvennt ee){ cpp.sttarttCloock((); sttartt.seetEnnablled((fallse)); sttop..settEnaableed(ttruee); } }}); sstopp.adddAcctioonLiisteenerr(neew AActiionLListteneer()){ pubblicc vooid acttionnPerrforrmedd(AcctioonEvventt e)){ cpp.sttopCClocck()); sttartt.seetEnnablled((truue);; sttop..settEnaableed(ffalsse);; } }}); //設(shè)設(shè)置面板板布局 JJPannel butttommPanne == neew JJPannel((); bbutttomPPanee.addd(sstarrt);; bbutttomPPanee.addd(sstopp); JJPannel conntenntPaane = nnew JPaanell();; cconttenttPanne.ssetLLayoout((neww BoordeerLaayouut())); cconttenttPanne.aadd((cp,,BorrderrLayyoutt.CEENTEER);; cconttenttPanne.aadd((butttommPanne,BBordderLLayoout..SOUUTH)); tthiss.seetCoonteentPPanee(coonteentPPanee); tthiss.seetReesizzablle(ffalsse);; } } //例程程9-66:CloockPPanee.jaava /*數(shù)字字時(shí)鐘面面板的實(shí)實(shí)現(xiàn)類**/ impoort javvax..swiing..JPaanell; impoort javva.uutill.*;; impoort javva.aawt..*; impoort javva.aawt..fonnt.FFonttRennderrConntexxt; impoort javva.aawt..geoom.**; impoort javva.ttextt.*;; publlic claass CloockPPanee exxtennds JPaanell immpleemennts Runnnabble { //線程程是否中中止的標(biāo)標(biāo)志 boooleaan rrunnningg = fallse;; //用于于顯示當(dāng)當(dāng)前時(shí)間間的字符符串 Strringg tiime = ""Cloock""; Fonnt ffontt = neww Foont(("SaanSeeriff", Fonnt.BBOLDD, 440);; //啟動(dòng)動(dòng)報(bào)時(shí)器器 pubblicc vooid staartCClocck()) { thhis..runnninng == trrue;; Thhreaad tt = neww Thhreaad(tthiss); t..staart((); } //終止止報(bào)時(shí)器器 pubblicc vooid stoopCllockk() { thhis..runnninng == faalsee; } //實(shí)現(xiàn)現(xiàn)Runnnabble接接口的rrun()方方法 pubblicc vooid runn() { whhilee (tthiss.ruunniing)) { //獲取取當(dāng)前時(shí)時(shí)間并轉(zhuǎn)轉(zhuǎn)換成字字符串 tthiss.tiime = DDateeForrmatt.geetTiimeIInsttancce()).foormaat(nnew Datte())); tthiss.reepaiint((); //讓當(dāng)當(dāng)前線程程休眠11秒鐘 ttry { Thrreadd.slleepp(10000)); }} caatchh (IInteerruupteedExxcepptioon ee) {{ e.pprinntSttackkTraace((); }} } } //輸出出當(dāng)前時(shí)時(shí)間 pubblicc vooid paiintCCompponeent((Graaphiics g) { suuperr.paainttCommponnentt(g)); Grraphhicss2D g2 = ((Graaphiics22D) g; g22.seetFoont((thiis.ffontt); FoontRRendderCConttextt coonteex == g22.geetFoontRRendderCConttextt();; Reectaanglle2DD booundd = thiis.ffontt.geetSttrinngBooundds(tthiss.tiime,, coonteex);; innt sstrXX = (innt) ((tthiss.geetWiidthh() - bbounnd.ggetWWidtth())) // 2)); innt sstrYY = (innt) ((tthiss.geetHeeighht()) - bouund..gettHeiightt())) / 2) + 440; g22.drrawSStriing((thiis.ttimee, sstrXX, sstrYY); } } //例程程9-77:IOOPippeDeemo..javva /*演示示采用管管道機(jī)制制的線程程間通信信*/ impoort javva.iio.**; publlic claass IOPPipeeDemmo{ publlic staaticc vooid maiin(SStriing[[] aargss){ try{{ //創(chuàng)建建并連接接管道 finaal PPipeedOuutpuutSttreaam ppoutt = neww PiipeddOuttputtStrreamm();; finaal PPipeedInnputtStrreamm piin == neew PPipeedInnputtStrreamm(poout)); //創(chuàng)建建并啟動(dòng)動(dòng)輸出線線程 Threead outtputtThrreadd = neww Thhreaad(nnew Runnnabble((){ publlic voiid rrun((){ writteByytess(poout)); } }); outpputTThreead..staart((); //創(chuàng)建建并啟動(dòng)動(dòng)輸入線線程 Threead inpputTThreead = nnew Thrreadd(neew RRunnnablle()){ publlic voiid rrun((){ readdByttes((pinn); } }); inpuutThhreaad.sstarrt()); }cattch((IOEExceeptiion e){{ e.prrinttStaackTTracce()); } } //往管管道中寫寫入數(shù)據(jù)據(jù) publlic staaticc vooid wriiteBBytees(OOutpputSStreeam outtstrreamm){ try{{ DataaOuttputtStrreamm ouut == neew DDataaOuttputtStrreamm( new BuffferredOOutpputSStreeam((outtstrreamm) ); Threead t == Thhreaad.ccurrrenttThrreadd ()); for((intt i==0; i<110; i+++){ Systtem..outt.prrinttln ("wwritte iinteegerr "++i+"" too piipe..");; out..wriiteIInt((i);; t.yiieldd ()); } out..fluush((); out..cloose((); Systtem..outt.prrinttln ("WWritte ddataa too piipe hass doone""); }cattch((IOEExceeptiion e){{ e.prrinttStaackTTracce()); } } //從管管道中讀讀取數(shù)據(jù)據(jù) publlic staaticc vooid reaadByytess(InnputtStrreamm innputtstrreamm){ try{{ DataaInpputSStreeam in = nnew DattaInnputtStrreamm( new BuffferredIInpuutSttreaam(iinpuutsttreaam) ); Threead t == Thhreaad.ccurrrenttThrreadd ()); boolleann eoof == faalsee; whille(!!eoff){ try{{ int i == inn.reeadIInt((); Systtem..outt.prrinttln(("Reead inttegeer ""+i++" ffromm piipe""); t.yiieldd ()); }cattch((EOFFExccepttionn e)){ eof = ttruee; } } Systtem..outt.prrinttln ("RReadd daata froom ppipee haas ddonee");; }cattch((IOEExceeptiion e){{ e.prrinttStaackTTracce()); } } } //例程程9-8 Heelloo_Worrld..javva impoort javvax..swiing..*; impoort javva.aawt..*; publlic claass Helllo__worrld exttendds JJAppplett{ publlic voiid ppainnt(GGrapphiccs gg){ g.drrawSStriing(("Heelloo,woorldd!",5,10)); } } HellloWoorldd.httml 代碼 <HTMML> <HEAAD><<TITTLE>>HELLLO,,WORRLD!!</TTITLLE><</HEEAD>> <BOODY>> <APPPLETT coode=="Heelloo_Worrld..claass"" wiidthh=3000 hheigght==3000><//APPPLETT> </BOODY>> </HTTML>>

注意事項(xiàng)

本文(Java程序設(shè)計(jì)教程 冶金工業(yè)出版社第9章pod)為本站會(huì)員(muj****520)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  sobing.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!