11.07.2015 Views

Writing Applications for mobile devices and reducing ... - NetBeans

Writing Applications for mobile devices and reducing ... - NetBeans

Writing Applications for mobile devices and reducing ... - NetBeans

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Write Once, Deploy AnywhereMediaControlSkin from the Configurationdrop-down menu in the IDE toolbar. Thenchoose Run>Run Main Project. It’s theA11AFigure 11Preprocessorcode.same TestMIDlet as be<strong>for</strong>e, but this timethe device emulator <strong>and</strong> its display arethinner – so we lose a little bit of the splashscreen, as shown in Figure 10.Preprocessing codePreprocessing modifies the code in yoursource files be<strong>for</strong>e the code is parsed bythe compiler. The preprocessor modifiesthe code according to preprocessor directivesyou insert into the code as codeblocks with beginning <strong>and</strong> ending directives.These code blocks are marked visuallyin the Source Editor <strong>and</strong> are includedA 10(or excluded) when you build the JAR <strong>for</strong> a specific project configurationor ability. You can use these code blocks to create, manage,<strong>and</strong> track code that is specific to one or more project configurationsor abilities.Now that we’ve defined the key concepts of project configurations,let’s go back to our example <strong>and</strong> say now that we want touse a different graphic <strong>for</strong> the MediaControlSkin device. We alreadyhave our two project configurations defined, so what we need todo is add some pre-processing code so that the compiler knowsit should use one image <strong>for</strong> DefaultConfiguration <strong>and</strong> another <strong>for</strong>MediaControlSkin.Click the Source button to view the TestMIDlet source code. Thenscroll down to the get_image1() method. Notice that some sectionshave a blue background – these are “guarded blocks” that are generatedby the VMD, <strong>and</strong> cannot be edited. Highlight the code beginningwith “//Insert pre-init code here <strong>and</strong> ending with “//Insertpost-init code here.” Right click on the selection <strong>and</strong> choose PreprocessorBlocks>Create If/Else Block. A menu with all the availableconfigurations <strong>and</strong> abilities appears. Double click on DefaultConfiguration.Your code should look like Figure 11.Notice that the //#else directive has a pink background. Thiscode can be edited. Change the graphic name “/<strong>mobile</strong>duke.png” to the name of another graphic (such as “/veryproudduke.AFigure 10TheMediaControlSkinEmulator.netbeans.org/kb/55/mobilitycdc.htmlMobilityPack <strong>for</strong> CDCdocumentationindexIssue Three N 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!