Tải bản đầy đủ (.pdf) (889 trang)

Swing hacks tips

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.62 MB, 889 trang )

SwingHacks
ByChrisAdamson,JoshuaMarinacci
...............................................
Publisher:O'Reilly
PubDate:June2005
ISBN:0-596-00907-0
Pages:542

TableofContents|Index

SwingHackshelpsJavadevelopersmovebeyondthebasicsofSwing,thegraphicaluser
interface(GUI)standardsinceJava2.Ifyou'reaJavadeveloperlookingtobuild
enterpriseapplicationswithafirst-classlookandfeel,Swingisdefinitelyoneskillyou
needtomaster.ThislatesttitlefromO'ReillyisareferencetothecoolstuffinSwing.It's
abouttheinterestingthingsyoulearnovertheyears--creative,original,evenweirdhacks-thethingsthatmakeyousay,"Ididn'tknowyoucouldevendothatwithSwing!"
SwingHackswillshowyouhowtoextendSwing'srichcomponentsetinadvancedand
sometimesnon-obviousways.ThebooktouchesupontheentireSwinggamut-tables,
trees,sliders,spinners,progressbars,internalframes,andtextcomponents.Detailisalso
providedonJTable/JTree,threadedcomponentmodels,andtranslucentwindows.You'll
learnhowtofilterlists,power-uptreesandtables,andadddrag-and-dropsupport.
SwingHackswillshowyouhowtodofunthingsthatwilldirectlyenhanceyourown
applications.Somearevisualenhancementstomakeyoursoftwarelookbetter.Someare
functionalimprovementstomakeyoursoftwaredosomethingitcouldn'tdobefore.Some
areevenjustplainsilly,inprintonlytoproveitcouldbedone.Thebookwillalsogiveyou
giveyouasmallglimpseoftheapplicationscominginthefuture.Newtechnologyis
streamingintotheJavacommunityatablisteringrate,anditgivesapplicationdevelopers
awholenewsetofblockstoplaywith.
Withitsprofusionoftipsandtricks,SwingHacksisn'tjustforthedeveloperwhowantsto
buildabetteruserinterface.It'salsoideallysuitedforclient-sideJavadeveloperswho
wanttodeliverpolishedapplications,enthusiastswhowanttopushJavaclientapplication
boundaries,andcoderswhowanttobringpowerfultechniquestotheirownapplications.


Whateveryourprogrammingneeds,SwingHacksispackedwithprogramminglessonsthat
increaseyourcompetencywithinterface-buildingtools.


SwingHacks
ByChrisAdamson,JoshuaMarinacci
...............................................
Publisher:O'Reilly
PubDate:June2005
ISBN:0-596-00907-0
Pages:542

TableofContents|Index




















































Credits
AbouttheAuthors
Contributors
Acknowledgments
Preface
WhySwingHacks?
HowtoUseThisBook
HowThisBookIsOrganized
ConventionsUsedinThisBook
UsingCodeExamples
HowtoContactUs
GotaHack?
SafariEnabled
Chapter1.BasicJComponents
Section1.1.Hacks112:Introduction
Hack1.CreateImage-ThemedComponents
Hack2.Don'tSettleforBoringTextLabels
Hack3.FillYourBorderswithPrettyPictures
Hack4.DisplayDatesinaCustomCalendar
Hack5.AddaWatermarktoaTextComponent
Hack6.WatermarkYourScrollPanes
Hack7.PutaNASAPhotointotheBackgroundofaTextArea
Hack8.AnimateTransitionsBetweenTabs
Hack9.BlurDisabledComponents
Hack10.BuildingaDrop-DownMenuButton
















































































Hack11.CreateMenuswithDropShadows
Hack12.AddTranslucencetoMenus
Chapter2.ListsandCombos
Section2.1.Hacks1320:Introduction
Hack13.FilterJLists
Hack14.AddaFilterHistory
Hack15.MakeJListsCheckable
Hack16.MakeDifferentListItemsLookDifferent
Hack17.ReorderaJListwithDrag-and-Drop
Hack18.AnimateYourJListSelections
Hack19.TurnMethodsintoListRenderers
Hack20.CreateaCollections-AwareJComboBox
Chapter3.TablesandTrees
Section3.1.Hacks2127:Introduction
Hack21.SizeYourColumnstoSuitYourJTable'sContents

Hack22.AddColumnSelectiontoJTables
Hack23.LetYourJTablesDotheSorting
Hack24.CreateaJDBCTableModel
Hack25.ExportTableDatatoanExcelSpreadsheet
Hack26.SearchThroughJTablesEasily
Hack27.AnimateJTreeDrops
Chapter4.FileChoosers
Section4.1.Hacks2832:Introduction
Hack28.AddaRight-ClickContextMenutotheJFileChooser
Hack29.DisplayShortcutsintheJFileChooser
Hack30.RealWindowsShortcutSupport
Hack31.AddImagePreviewtoFileChoosers
Hack32.PreviewZIPandJARFiles
Chapter5.Windows,Dialogs,andFrames
Section5.1.Hacks3340:Introduction
Hack33.WindowSnapping
Hack34.MakeaDraggableWindow
Hack35.AddWindowsResizeIcons
Hack36.AddStatusBarstoWindows
Hack37.SaveWindowSettings
Hack38.EarthquakeDialog
Hack39.SpinOpenaDetailPane
Hack40.MinimizetoaMini-Frame
Chapter6.TransparentandAnimatedWindows

















































































Section6.1.Hacks4147:Introduction
Hack41.TransparentWindows
Hack42.MakeYourFrameDissolve
Hack43.CreateCustomToolTips
Hack44.TurnDialogsintoFrame-AnchoredSheets
Hack45.AnimatingaSheetDialog
Hack46.SlideNotesOutfromtheTaskbar
Hack47.IndefiniteProgressIndicator
Chapter7.Text
Section7.1.Hacks4855:Introduction
Hack48.MakeTextComponentsSearchable
Hack49.ForceTextInputintoSpecificFormats
Hack50.Auto-CompletingTextFields
Hack51.WriteBackwardText
Hack52.UseHTMLandCSSinTextComponents
Hack53.UseGlobalAnti-AliasedFonts
Hack54.Anti-AliasedTextWithoutCode
Hack55.Anti-AliasedTextwithaCustomLookandFeel

Chapter8.Rendering
Section8.1.Hacks5664:Introduction
Hack56.CreateaMagnifyingGlassComponent
Hack57.CreateaGlobalRight-Click
Hack58.BlockaWindowWithoutaModalDialog
Hack59.CreateaColorEyedropper
Hack60.ChangingFontsThroughoutYourApplication
Hack61.LoadNewFontsatRuntime
Hack62.BuildaColorfulVector-BasedButton
Hack63.AddaThirdDimensiontoSwing
Hack64.TurntheSpotlightonSwing
Chapter9.Drag-and-Drop
Section9.1.Hacks6569:Introduction
Hack65.Drag-and-DropwithFiles
Hack66.HandleDroppedURLs
Hack67.HandleDroppedImages
Hack68.HandlingDroppedPictsonMacOSX
Hack69.TranslucentDrag-and-Drop
Chapter10.Audio
Section10.1.Hacks7078:Introduction
Hack70.PlayaSoundinanApplet











































































Hack71.PlayaSoundwithJavaSound
Hack72.PlayaSoundwithJavaMediaFramework
Hack73.PlayaSoundwithQuickTimeforJava
Hack74.AddMP3SupporttoJMF
Hack75.BuildanAudioWaveformDisplay
Hack76.PlayNon-TrivialAudio
Hack77.ShowAudioInformationWhilePlayingSoundHack
Hack78.ProvideAudioControlsDuringPlayback
Chapter11.NativeIntegrationandPackaging
Section11.1.Hacks7987:Introduction
Hack79.LaunchExternalProgramsonWindows
Hack80.OpenFiles,Directories,andURLsonMacOSX
Hack81.MakeMacApplicationsBehaveNormally
Hack82.ControliTunesonMacOSX
Hack83.ControliTunesUnderWindows
Hack84.ConstructSingle-LaunchApplications
Hack85.StuffStuffinJARs
Hack86.MakeQuickLookandFeelChanges
Hack87.CreateanInverseBlack-and-WhiteTheme
Chapter12.Miscellany
Section12.1.Hacks88100:Introduction
Hack88.DisplayaBusyCursor
Hack89.FunwithKeyboardLights
Hack90.CreateDemonstrationswiththeRobotClass
Hack91.CheckYourMailwithSwing
Hack92.Don'tBlocktheGUI
Hack93.CodeModelsThatDon'tBlock

Hack94.FireEventsandStayBugFree
Hack95.DebugYourGUI
Hack96.DebugComponentswithaCustomGlassPane
Hack97.MirroranApplication
Hack98.AddVelocityforDynamicHTML
Hack99.GetLargeFileIcons
Hack100.MakeFramesResizeDynamically
Colophon
Index


Credits
AbouttheAuthors
Contributors
Acknowledgments


AbouttheAuthors
JoshuaMarinaccistartedplayingwithJavainthesummerof'95
attherequestofhisfavoriteTAandhasneverlookedback.
SincethenhehasbuiltallmannerofJavasoftwareforclients
rangingfromlargeFortune500companiestosmallInternet
startups.Hequicklydiscoveredhispassionforuserinterfaces
andclientsoftware,buildingareputationinthedesktopJava
worldandfinallyjoiningtheSwingTeamatSuninthespringof
2005.Inhissparetime,Joshuawritesarticlesandweblogsfor
Java.netwhilecontributingtotheJDIC,JDNC,andWinLAFopen
sourceprojects.HealsoheadsupFlyingSaucer,anopen
source,all-JavaXHTMLrenderer.Thisishisfirstbook,but
hopefullynothislast.HelivesinhistoricEastAtlantawithhis

girlfriendKimandtheiryellowlabradorEliza.
ChrisAdamsonistheEditorofO'Reilly'sONJavasiteandthe
AssociateOnlineEditorforJava.net,acollaborationofO'Reilly,
SunMicrosystems,andCollabNet.HealsowritesaboutJava
andMactopicsonlineandspeaksatconferencessuchas
ADHOC/MacHackandtheO'ReillyMacOSXConference.He
developsmediaapplicationsundertheguiseofhisconsulting
company,Subsequently&Furthermore,Inc.HehasanM.A.in
TelecommunicationsfromMichiganStateUniversityandaB.A.
inEnglishandB.S.inSymbolicSystemsfromStanford
University.HelivesinAtlantawithhiswife,Kelly,andtheir
children,KeaganandQuinn,andhehasthusfarmanagedto
ownsevenandahalfMacs.


Contributors
Swingisbigenoughthatsurelyeveryonewhoworkswithit
takesawaysomenewideasforhowtohackit.Ourcontributors
helpedfleshthisbookoutwithhacksthatblewusawayand
thatwe'resureyou'lllike,too.
RomainGuyisaFrenchstudentcurrentlyworkingasan
internwiththeSwingTeamatSunMicrosystemsin
California.HediscoveredJavain1998andcontributedto
theOpenSource/FreeSoftwarecommunitywithJext,a
Javasourcecodeeditorhedevelopedoverfiveyears.Heis
alsoafreelancejournalistforLogin:,aFrenchcomputing
magazine.Nevershortforideas,healsowrotefor
Javalobby,theJavadeveloper'sjournal,andacoupleof
Frenchmagazines.Romainseeksforotherexperiences
wheneverhecan:heworksasatranslatorforO'Reilly

France,hetaughtJavainaFrenchuniversity,hefulfilled
severalmissionsasafreelanceJavadeveloper,andheeven
workedasavideogameprogrammer.Today,Romain
focusesonUIdesignandhumaneinteraction.Heshareshis
workonhisweblog:www.jroller.com/page/gfx.
JonathanSimonisacomprehensiveclient-sideexpert,
designinganddevelopingmission-criticalfinancialtrading
clientsforWallStreetinvestmentbanks.Thisrequiresa
fluidcombinationofbusinessandtaskanalysisand
interactiondesignwiththeintricaciesofJavarich-client
developmenttocreatecontentrich,ergonomictrading
applications.Hehaswrittenextensivelyabouthis
experiencesforJava.net,IBMDeveloperWorks,JavaWorld,
andAddisonWesley.Anavidpercussionist,composer,and
electronicmusician,Jonathanalsodevelopsmusicsoftware
inJava.Heisespeciallyinterestedininteractiondesignand
datavisualization.


Acknowledgments
Joshua
ThisbookhasgonefasterthatIeverimagined,fromoriginal
concepttofinaldraftinlessthanayear.WritingSwingHacks
washarderthanIeverthought,givingmegreatrespectfor
thosewhowritecompletenovels.Ihavehadtheutmostfun,
however,andwouldn'ttradetheexperiencefortheworld.
IwouldfirstliketothankKimi,mylovingpartnerwho
convincedmetopursuewritingasaseriousendeavor.Shehas
alwaysbelievedthatIcouldbemorethanjustacontractcoder.
Icouldn'thavedoneitwithoutyou,Sweetie.

ManythankstomyfamilyandfriendswhoalwayssaidthatI
wasneverlivinguptomypotential.Thankyouforraising,
loving,andteachingme.Ipromisetoliveuptomypotential
now,startingnextweek.
ThankstothegreatteamatO'Reilly,especiallyBrett,who
tirelesslyreadthroughmydrafts,dottedthets,crossedtheis,
andmademyprosereadable.
ThanksgoouttothereadersofJava.netandDanielSteinberg,
myJava.neteditor,whohavealwaysprovidedencouragement,
feedback,andconstructivecriticism.WithouttheJava
community'secologyofcodeandfreshideas,thisbook
wouldn'thavebeenpossible.
SpecialthankstoJonathanandRomainwhogaveustheboost
weneededtogetthebookfinished.They'veputinsomegreat
stuff.I'veevenlearnedafewthings.
ExtraspecialthankstoChriswhobelievedfromthestartthat


thiswasagreatideaforabook.Heguidedmethroughthe
proposalprocess,shapedourdraft,andalwayskeptthebook
ontrack.MaybewecanfinallygetthatOkamaGameSphere.
And,finally,myunendingthankstoalloftheSwingTeam
developerswhoputin10yearsofbloodandsweat,making
Swingthepowerfultoolkititistoday.Ihopewecankeep
pushingitforward.

Chris
CreditforthisbookneedstobeginwithJoshuaI'mstilltempted
totype"Joshy"becausethat'shisusernameeverywherewho
startedthisbookasaninformalseriesonhispopularJava.net

weblogandhadthewherewithaltopushthroughabook
proposal.
Also,allthereallycoolhacksarehis.ButIthinkthat'swhat
everyoneinvolvedwiththisbookhasbeensayingwhenthey
readwhattheothershavecontributed.
Andspeakingofthem,thanksalsotoourcontributors,Romain
andJonathan,whocameinatjusttherighttimetogetthis
bookoverthehumpandmakeitreal.Theirinventivenessand
responsivenesshelpeduspullthrough.
ThankstoBrettMcLaughlin,whowasonthereceivingendofa
prettywildbrain-dump,withtwoauthorsandtwocontributors
goingonwildlydifferenttangents.Hehelpedshapethisbook
intosomethingreadableandfun.
LotsofotherpeopleinO'Reillyproductionwillhandlethisbook
afterIfinishwritingthisacknowledgment,andIthankthemin
advanceforeverythingtheydo.
And,ofcourse,thankstoKellyandKeaganforholdingdownthe


fortathomewhiledaddywasintheofficeworkingonthisbook.
Quinnalsocontributed,sleepingonmylapwhileIbangedout
partsofChapters10and11.
ObligatoryO'Reillytunecheck:thistimeitwasDelgados,The
Tubes,GreenDay,L'Arc~en~Ciel,DavidBowie,FrankZappa,
PuffyAmiYumi,LittleFeat,theGundamWingEndlessWaltz
soundtrackandtheArmitage'sDimensionstream.


Preface
Hi,welcometoSwingHacks!Thisbookisareference,butnota

completereferenceoftheSwingAPI.Wealreadyhavethat.It's
calledJavaSwing,ispublishedbyO'Reilly,andweighsinat
over1,200pages.It'savailableforpurchaseatfinebookstores
andRussianblackmarketwebsiteseverywhere.We'renot
sayingthatitisn'tagreatbook.It'sfantastic!We'veowned
manyweatheredcopiesovertheyears.Theproblemis…it's
huge!Thisisn'treallythebook'sfault:Swingitselfishuge.I
oncesawanAPIdiagramthattookanentire30-inchposter.
Swingispowerful,butittakesalongtimetoexplorefully,
simplybecauseitissobig.That'snotwhatthisbookisabout.
Thisbookisareferencetothecoolstuff.It'saboutthe
interestingthingsyoulearnovertheyears.Theweirdhacks
thatmakeyousay,"Ididn'tknowyoucouldevendothat!"
AfteryearsofworkingwithSwing,youstarttolearnwhatthe
APIisgoodatandwhatitlacks.Somedaysyoulearn
somethingthatmakesyourlifeasadevelopereasier,awayto
dosomethingquickerthanthestandardroute.That'swhatwe
putintothisbook.Somedaysyoulearnaworkaroundfora
long-standingbugoramissingfeaturethatyou'vebeendying
tohave.Weputthatstuffinthebook,too.Sometimesit's
somethingfunaninterestingAPIthatmakesusthink,"Well,if
wewereevilwhatcouldwedowithit?"Thisisusuallyfollowed
bythepinkieuptothemouthandcacklingthatcanbeheard
outsideourundergroundlair.Aftermuchconsultationwith
lawyersandgods,weslippedsomeoftheseintothebook,too.


WhySwingHacks?
Thetermhackinghasabadreputationinthepress.Theyuseit
torefertopeoplewhobreakintosystemsorwreakhavocwith

computersastheirweapon.Amongpeoplewhowritecode,
though,thetermhackreferstoaquick-and-dirtysolutiontoa
problem,oracleverwaytogetsomethingdone.Andtheterm
hackeristakenverymuchasacompliment,referringto
someoneasbeingcreative,havingthetechnicalchopstoget
thingsdone.TheHacksseriesisanattempttoreclaimthe
word,documentthegoodwayspeoplearehacking,andpass
thehackerethicofcreativeparticipationontotheuninitiated.
Seeinghowothersapproachsystemsandproblemsisoftenthe
quickestwaytolearnaboutanewtechnology.
Intheshortterm,wehopethisbookwillshowyouhowtodo
funthingsthatwillenhanceyourownapplicationsdirectly.
Somearevisualenhancementstomakeyoursoftwarelook
better.Somearefunctionalimprovementstomakeyour
softwaredosomethingitcouldn'tdobefore.Someareevenjust
plainsilly,inprintonlytoproveitcouldbedone.Whateveryour
interest,wehopeyouwillfindbothbetterwaysofdoingold
thingsandlearnsomethingnewabouttechniquesyounever
eventhoughtof.
Inthelongterm,wehopethisbookwillgiveyouasmall
glimpseoftheapplicationscominginthefuture.Thisyear
(2005)wehopewillbeawatershedyearforJavaonthe
desktop.Usersaredemandingmoreadvanceduserinterfaces
thantheWebcanprovide,andJavaispoisedtoprovidethem.
NewtechnologyisstreamingintotheJavacommunityata
blisteringrate,anditgivesapplicationdevelopersawholenew
setofblockstoplaywith.Thisisimportantbecauseweare
goingtoneedthesenewtechnologies.
Newdesktopsoftwarepromisesgreaterintegrationbetweenthe



Web,externaldevices,andsoftwaresittingrightonyour
desktop.RSSreadersandiPods.iTunesandphotocollaboration.
Gamingondesktops,servers,andcellphones;allatthesame
time.Thisisthefutureofdesktopsoftware.Swingisjusta
smallpartofdesktopJava,butwefeelitisthefocalpointthe
placewheredesktoptechnology(AWT,Java2D,JavaSound),
networktechnology(webservices,XML,JXTA),anddevice
technology(iPods,cellphones,TVs)allconvergeuponJava.
ManyofthehacksinthisbookarenotstrictlyaboutSwing,but
aboutusingSwingtodocoolthingswiththerestoftheworld.
Andit'smorethanjust"cool"animationisapowerfulwayto
showachangeincontentorcontext,andsoundcangetthe
user'sattentionwhenheorsheisawayfromthekeyboard.
Thesefeaturesareimportantpartsofdeliveringuser-centric,
qualitydesktopapplications.


HowtoUseThisBook
Youcanreadthisbookfromcovertocoverifyoulike,buteach
hackstandsonitsown,sofeelfreetobrowseandjumptothe
differentsectionsthatinterestyoumost.Ifthere'sa
prerequisiteyouneedtoknowabout,acrossreferencewill
guideyoutotherighthack.Thecodeallworks(wetriedit)but
incaseyoucan'tgetahacktowork,letusknowatthebook's
website:Youcan
alsodownloadthebook'scodeonline,orcontributeyourown
tipsandtricks.Ifwecollectenoughnewmaterial,andthisbook
sellsmorethan10copies,thenthepublishersmightletus
makeSwingHacks2:TheEndlessRepaint.

Withfewexceptions,thehacksinthisbookwerewrittenfor
Java2StandardEdition(J2SE),version1.4,whichyoucanget
fromAfewhacksdependonopen
sourcepackages,whicharefreelydownloadablefromtheir
homepages,asdescribedinthehackitself.Theonlyexceptions
aretwohacksthatuseQuickTimeforJavathisisfreelyavailable
fromApple(andinstalledbydefaultonMacOSX),butitis
proprietaryandavailableforMacandWindowsonly.
BecausethisisabookaboutSwing,theprogramlistingswillbe
usingtheclassesfromtheSwingandAWTpackages,sowe've
skippedimportjavax.swing.*andimportjava.awt.*statementsfor
space.Youcanalsoassumethatanylistinginvolvingevent
handlingwillimportjava.awt.event.*andprobablyimport
javax.swing.event.*aswell.Java2Dhacksimplicitlyimport
java.awt.image.*.Inshort,we'llincludeimportstatementsonly
whenahackinvolvesnon-core,and/ornon-obviousimports,
likethehacksthatuseJDBC,Lucene,Velocity,QuickTimefor
Java,etc.


HowThisBookIsOrganized
Thebookisdividedintoseveralchapters,organizedbysubject:

Chapter1,BasicJComponents
Hereyou'llfindsimplehacksforthebasiccomponentslike
labels,buttons,andtextfields.Thischaptercontainsalot
ofbangforthebuck,anditillustratessomeofthe
techniquesthatwewillexploremorefullylateron.From
fancyJLabelstotranslucentmenus,thisisagreatplaceto
start.


Chapter2,ListsandCombos
ThischapterfeaturescomplicatedSwingcomponentsthat
areusedeverywhere.Bendthemtoyourwill!Makethem
lookgoodwithpolymorphicrenderersandanimated
selections.Makethemperformwellwithfilteringand
Collectionssupport.

Chapter3,TablesandTrees
Thischapterrevelasthesecretsofthesemystic
componentsfromExcelexportingtoproperJTreedrop
targets.MaketheJTreeandJTabledance.

Chapter4,FileChoosers


OneofSwing'smostmalignedcomponents,the
JFileChooser,actuallyhasalotofpowerhidinginsidesome
murkyAPIs.Thischapterwillletyouusecustomicons,
detectWindowsshortcuts,andevennavigateZIPfiles.

Chapter5,Windows,Dialogs,andFrames
Thisiswherethefunbegins.Everyapplicationneedsa
container,sowhynotmakeitprettyandpowerful?Make
yourwindowsdragandsnap.Buildcustomwindowslikethe
earthquakeloginandspinopendialog.Youcanevensave
yourwindowsettingsautomaticallywithalmostnocode
changes.

Chapter6,TransparentandAnimatedWindows

Ifyouwentthroughthepreviouschapterandstillwant
more,thenthischapterisforyou.Wepushwindowstothe
limitwithtransparency,animations,slide-inOSX
stylesheets,andsomeofthecoolestspecialeffectsyou've
everseen.

Chapter7,Text
Textcomponentsseemboring,butthere'salotofpower
hidinginthere.Thischapterwillshowyouhowtodo
regularexpressionsearching,dotcompletion,backward
text,andeventhreedifferentwaystogiveyourapplication
thebrightsheenofanti-aliasing.

Chapter8,Rendering


Thischapterhasthemeatofthegraphicshacks.Custom
fonts,amagnifyingglass,vectorbuttons,andevensome
workwithJava3D.We'vegotsomegreatthingstomake
yourapplicationpop.

Chapter9,Drag-and-Drop
Whenyouruserswanttwopiecesofsoftwaretowork
togetherthefirstthingtheywanttodoisdrag-and-drop
datafromtheirotherprogramstoyours.Thischapter
covershowtodorobustandattractivedrag-and-drop
entirelywithinJava.

Chapter10,Audio
Whatwouldbeacoolmodernapplicationwithoutsome

mediasupport?Thischaptercoversfourdifferentwaysto
playsound,howtodisplaywaveforms,andhowtoembed
MP3supportinyourownprograms.

Chapter11,NativeIntegrationandPackaging
Thebestsoftwareworkswellwiththenativeoperating
system.Hereyou'lllearnhowtolaunchwebbrowsers,hack
theWindowsregistry,customizeyourprogramforspecific
platforms,andevencontroliTunes.

Chapter12,Miscellany
Thischapteroffersagrabbagofthingsthatdidn'tfit
anywhereelse,butweretoocoolnottoinclude.Animated


cursors,betterthreading,flashingthekeyboardlights,and
abunchofquickone-linerstoletyoumakethemostof
yourbusyday.


ConventionsUsedinThisBook
Thefollowingisalistofthetypographicalconventionsusedin
thisbook:

Italics
UsedtoindicateURLs,filenames,filenameextensions,and
directory/foldernames.Apathinthefilesystemwillappear
as/Developer/Applications,forexample.

Constantwidth

Usedtoshowcodeexamples,thecontentsoffiles,and
consoleoutput,aswellasthenamesofvariables,
commands,andothercodeexcerpts.

Constantwidthbold
Usedtohighlightportionsofcode,typicallynewadditionsto
oldcode.

Constantwidthitalic
Usedincodeexamplesandtablestoshowsampletextto
bereplacedwithyourownvalues.

color


Thesecondcolorisusedtoindicateacross-referencewithin
thetext.
Youshouldpayspecialattentiontonotessetapartfromthe
textwiththefollowingicons:

Thisisatip,suggestion,orgeneralnote.Itcontainsuseful
supplementaryinformationaboutthetopicathand.

Thisisawarningornoteofcaution,oftenindicatingthatyourmoney
oryourprivacymightbeatrisk.

Thethermometericons,foundnexttoeachhack,indicatethe
relativecomplexityofthehack:
beginner moderate expert



UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"SwingHacksbyJoshuaMarinacciandChris
Adamson.Copyright2005O'ReillyMedia,Inc.,0-596-00907-0."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat



HowtoContactUs
Wehavetestedandverifiedtheinformationinthisbooktothe
bestofourability,butyoumayfindthatfeatureshavechanged
(oreventhatwehavemademistakes!).Asareaderofthis
book,youcanhelpustoimprovefutureeditionsbysendingus
yourfeedback.Pleaseletusknowaboutanyerrors,
inaccuracies,bugs,misleadingorconfusingstatements,and

typosthatyoufindanywhereinthisbook.
Pleasealsoletusknowwhatwecandotomakethisbookmore
usefultoyou.Wetakeyourcommentsseriouslyandwilltryto
incorporatereasonablesuggestionsintofutureeditions.Youcan
writetousat:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
(800)998-9938(intheU.S.orCanada)
(707)829-0515(international/local)
(707)829-0104(fax)
Toasktechnicalquestionsortocommentonthebook,send
emailto:

ThewebsiteforSwingHackslistsexamples,errata,andplans
forfutureeditions.Youcanfindthispageat:
/>Formoreinformationaboutthisbookandothers,seethe
O'Reillywebsite:



GotaHack?
ToexploreHacksbooksonlineortocontributeahackforfuture
titles,visit:



SafariEnabled

WhenyouseeaSafari®Enabledicononthecoverof

yourfavoritetechnologybook,thatmeansthebookisavailable
onlinethroughtheO'ReillyNetworkSafariBookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual
librarythatletsyoueasilysearchthousandsoftoptechbooks,
cutandpastecodesamples,downloadchapters,andfindquick
answerswhenyouneedthemostaccurate,currentinformation.
Tryitforfreeat.


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×