DOC PREVIEW
Purdue ECE 462 - Static Members and Sharing in Java

This preview shows page 1-2-3-4-5-34-35-36-37-38-69-70-71-72-73 out of 73 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Static Members and Sharing in JavaObject Creation in JavaStatic Member and Memory SharingGame ProgramsDeveloping Complex ProgramsJava GamesApplet GameWindow GameFull Screen GameFull-Screen GamesCreate a Java Project in Netbeans using Existing CodeFull Screen TestAnti AliasDisplay ImagesLoad and Display ImagesAnimationSynchronized MethodsECE 462ECE 462Object-Oriented Programmingusing C++ and Javausing C++ and JavaSt ti M b dStatic Members and Sharing in JavaYung-Hsiang Lul@ d [email protected] Static Member and Sharing in Java 1YHL Static Member and Sharing in Java 2Object Creation in JavaObject Creation in Java• Java does not automatically create copy constructors.ypy• Objects must be created using new; therefore, u2 is not a separate object.• Objects, once created, do not share attributes. Changing one does not affect another.•Java does not allow operator overloading by•Java does not allow operator overloading by programmers. Hence, it is not possible to redefine operator =.• In Java, operator = does not perform copy. It creates "alias". The previous object becomes garbage.YHL Static Member and Sharing in Java 3Static Member and Memory SharingYHL Static Member and Sharing in Java 4YHL Static Member and Sharing in Java 5YHL Static Member and Sharing in Java 6YHL Static Member and Sharing in Java 7Self TestSelf TestYHL Static Member and Sharing in Java 8ECE 462Object-Oriented Programmingusing C++ and JavaGame ProgramsYHL Game Programs 1Game ProgramsYung-Hsiang [email protected] Complex Programs(Using Games as Examples)YHL Game Programs 2Java Games• Applet games: running through web browser+ no installation needed, easy upgrade (the web version is always the latest)– security restrictions, cannot save game status•Window games:YHL Game Programs 3•Window games:+ no restrictions like applets– players may be distracted by other windows• Full-screen games:+ no other program can appear to distract players– do not allow players to engage in other activities (such as instant messaging)Applet GameYHL Game Programs 4YHL Game Programs 5YHL Game Programs 6YHL Game Programs 7YHL Game Programs 8YHL Game Programs 9Window GameYHL Game Programs 10YHL Game Programs 11Full Screen GameYHL Game Programs 12YHL Game Programs 13YHL Game Programs 14YHL Game Programs 15YHL Game Programs 16YHL Game Programs 17YHL Game Programs 18YHL Game Programs 19YHL Game Programs 20YHL Game Programs 21ECE 462Object-Oriented Programmingjggusing C++ and JavaFull-Screen GamesYung-Hsiang Lul@ d [email protected] Full-Screen Games 1Create a Java Project in Netbeansusing Existing CodeYHL Full-Screen Games 2YHL Full-Screen Games 3YHL Full-Screen Games 4YHL Full-Screen Games 5YHL Full-Screen Games 6YHL Full-Screen Games 7YHL Full-Screen Games 8Full Screen TestFull Screen TestYHL Full-Screen Games 9YHL Full-Screen Games 10YHL Full-Screen Games 11on some machines,th b k dthe background appears blackYHL Full-Screen Games 12YHL Full-Screen Games 13YHL Full-Screen Games 14YHL Full-Screen Games 15YHL Full-Screen Games 16YHL Full-Screen Games 17Anti AliasAnti AliasYHL Full-Screen Games 18notice the stairs in WYHL Full-Screen Games 19ithignore the errorsreported by Netbeans.This program is builtpgusing ant.YHL Full-Screen Games 20YHL Full-Screen Games 21Display ImagesDisplay ImagesYHL Full-Screen Games 22Image TypesImage TypestransparentopaquetranslucentYHL Full-Screen Games 23Load and Display ImagesLoad and Display ImagesYHL Full-Screen Games 24YHL Full-Screen Games 25YHL Full-Screen Games 26YHL Full-Screen Games 27change nameto runTest."run" is a functionof Java Thread.of Java Thread.YHL Full-Screen Games 28YHL Full-Screen Games 29YHL Full-Screen Games 30YHL Full-Screen Games 31AnimationAnimationYHL Full-Screen Games 32AnimationAnimation• Change frames with small differences quickly. gqy• The time in each frame may be different.YHL Full-Screen Games 33need to specify the class, otherwise compiler warningotherwise, compiler warningYHL Full-Screen Games 34> javac-Xlint:unchecked Animation java> javac -Xlint:unchecked Animation.javaAnimation.java:34: warning: [unchecked] unchecked call to add(E) as a member of the raw type jtilALitjava.util.ArrayList frames.add(new AnimFrame(image, totalDuration));))YHL Full-Screen Games 35YHL Full-Screen Games 36YHL Full-Screen Games 37YHL Full-Screen Games 38frame 0 1 2 3 4duration(ms)150 250 300 150 200endTime1504007008501050• animTime = 600 ⇒–animTime > 150? Yes index ++⇒index = 1endTime1504007008501050–animTime > 150? Yes, index ++ ⇒index = 1– animTime > 400? Yes, index ++ ⇒ index = 2– animTime > 700? No, index = 2• animTime = 2900 ⇒ 2 iterations = 2100– animTime = 2900 % 1050 = 800, index = 0–animTime>150? Yes, index++⇒index=1animTime 150? Yes, index ⇒index 1– animTime > 400? Yes, index ++ ⇒ index = 2– animTime > 700? Yes, index ++ ⇒ index = 3animTime > 850? No index 3YHL Full-Screen Games 39–animTime > 850? No, index = 3Synchronized MethodsSynchronized Methods•At any moment, only one of each object's synchronized y,y jymethods can execute.Animation anim = new Amination();anim.addFrame(...);anim addFrame( );the execution time ofanim.addFrame(...);...anim update( );the execution time ofsynchronized methodscannot overlapanim.update(...);• Since the program is not multi-thread, it is unnecessary YHL Full-Screen Games 40pgyto make methods synchronized.YHL Full-Screen Games 41YHL Full-Screen Games 42YHL Full-Screen Games 43YHL Full-Screen Games


View Full Document

Purdue ECE 462 - Static Members and Sharing in Java

Download Static Members and Sharing in Java
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Static Members and Sharing in Java and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Static Members and Sharing in Java 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?