Скачать презентацию Lec 08 Agenda Go over exam More Java Скачать презентацию Lec 08 Agenda Go over exam More Java

1abbcef50beb6bba89c378ccb27edab9.ppt

  • Количество слайдов: 55

Lec 08 Agenda Go over exam More Java Swing examples pro. Blackjack (lab 09 Lec 08 Agenda Go over exam More Java Swing examples pro. Blackjack (lab 09 g: lec 08/glab/blackjack/) Introduction to pro. Final (Game Features) Java. FX

The game of Black. Jack 21. Create a game of Black. Jack. User plays The game of Black. Jack 21. Create a game of Black. Jack. User plays against the computer which is the dealer. You must create a GUI application. This project provides an excellent opportunity to use your OO Analysis and Design skills, as well as your Swing-GUI skills. Here are the rules of blackjack: http: //en. wikipedia. org/wiki/Blackjack To keep things simple, you should use a 6 -Deck shoe. No splits No insurance User starts with 1000$ You must respect hard and soft aces (either 1 or 11) Dealer must hit on soft 17 There are many resource online where you can find png's or jpg's or cards.

Describe the system: The game of Black. Jack; a single player plays against the Describe the system: The game of Black. Jack; a single player plays against the house for money. His bet is consistently $100. 00 and he starts with 1, 000. There is a shoe of six 52 -card decks which is reshuffled when the shoe is half used. If the player wins the hand, his gets his bet back plus the amount of the bet. If he loses, he loses the money, and if he gets blackjack, he get's his bet * 1. 5. The player plays against a dealer who must follow the following strict rules; aces are worth 11 points only, and the dealer must hit on 16 or below. The player however, is allowed to hit or hold on any hand-value. Furthermore, aces are worth either 1 or 11, whichever is more advantageous. An initial two hands are dealt on seperate sides of a table consisting of two cards apiece. The dealer's hand displays only one card up. The player has the option to hit, hold, split, double-down, buy insurance, etc. For this initial version of the game, we'll consider only hit, hold, and deal. blue are nouns (objects or fields)

Java. FX is … • Cross platform: Windows GA, Mac & Linux Dev. Preview Java. FX is … • Cross platform: Windows GA, Mac & Linux Dev. Preview • Familiar: 100% Java APIs • Powerful: leverages underlying Java platform • Modern: CSS skinning, HW acceleration, Webkit • Backwards ‘compatible’: Swing & SWT interoperability • Flexible: applicable to embedded, tablets and mobile • Open Source: http: //openjdk. java. net/projects/openjfx

5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection 5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Java. FX: Java's new Rich Client Platform Presenting with LOGO 6 Copyright © 2011, Java. FX: Java's new Rich Client Platform Presenting with LOGO 6 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Java Pioneered Rich Client Applications But developers had to learn multiple technologies Java Pioneered Rich Client Applications But developers had to learn multiple technologies

Tutorial and API Docs http: //docs. oracle. com/javase/8/javafx/get-started-tutorial/ http: //docs. oracle. com/javase/8/javaseclienttechnologies. htm http: Tutorial and API Docs http: //docs. oracle. com/javase/8/javafx/get-started-tutorial/ http: //docs. oracle. com/javase/8/javaseclienttechnologies. htm http: //download. oracle. com/otndocs/products/javafx/2/samples Ensemble – Collection of Examples /Ensemble/index. html Videos on Java. FX https: //www. youtube. com/user/Oracle. Learning/search? query=j avafx 8 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Java. FX Simplifies Application Development Developers Focus on Capabilities Instead of Technologies Java. FX Simplifies Application Development Developers Focus on Capabilities Instead of Technologies

10 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection 10 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

11 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection 11 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Java. FX Runtime High Level Architecture Java. FX Glossary • Glass Windowing Toolkit: Provides Java. FX Runtime High Level Architecture Java. FX Glossary • Glass Windowing Toolkit: Provides native operating services, such as managing the windows, timers, and surfaces • Prism: Graphics pipeline that can run on hardware and software renderers • Quantum Toolkit: Ties Prism and Glass together and makes them available to the Java. FX APIs • This is completey seemless in Java 8

Java. FX 2. 0 Scoreboard Released on time (October 2011) ✔ All functionality exposed Java. FX 2. 0 Scoreboard Released on time (October 2011) ✔ All functionality exposed through Java APIs ✔ Java. FX and Java. Script/HTML 5 interoperability ✔ High performance 2 D and 3 D graphics engine ✔ Designed to exploit modern advances in desktop and mobile ✔ Make Java. FX UI Controls available open source ✔ Complete and integrated development lifecycle experience ✔ Done In progress

Java APIs and FXML Java APIs for Java. FX FXML • End-to-end Java development Java APIs and FXML Java APIs for Java. FX FXML • End-to-end Java development • Java language features - generics, annotations, multi-threading • Fluent API for UI construction • Alternative JVM supported languages (e. g. Groovy, Scala) with Java. FX • Leverage sophisticated Java IDEs, debuggers and profilers • Java APIs preserve convenient Java. FX Script features (e. g. , bind) • Scriptable, XML-based markup language for defining UI • Convenient alternative to developing UI programmatically in Java • Easy to learn and intuitive for developers familiar with web technologies or other markup based UI technologies • Powerful scripting feature allows embedding scripts within FXML. Any JVM scripting language can be used, including Java. Script, Groovy, and Scala

Graphics and Media New Graphics Pipeline • New hardware accelerated graphics pipeline (Prism) • Graphics and Media New Graphics Pipeline • New hardware accelerated graphics pipeline (Prism) • New windowing toolkit (Glass) for Prism • Java 2 D software pipeline under Prism • High-level support for making rich graphics simple • Shadows, Blurs, Reflections, Effects, 2 D transforms • 3 D Transforms today; Full 3 D objects in future Media • Stable media framework based on GStreamer • VP 6, MP 3 playback of Web multimedia content • Low latency audio • Alpha channel support • Performance improvements • Full screen video

Web. View and Swing Interoperability Web. View Component • Embed Web content in Java. Web. View and Swing Interoperability Web. View Component • Embed Web content in Java. FX applications • HTML rendering based on Webkit • Hardware accelerated rendering using PRISM • DOM access and manipulation Swing and SWT Interop • Embed Java. FX content into existing Swing applications • Extend existing Swing applications with new Java. FX features such as Web. View and high -performance graphics • Applies to SWT applications as well Browser Plugin • Faster loading of Java. FX Web applications based on Prism • Pre-loader for improved user experience with Java. FX Web applications

Open Source and Standardization • Java. FX source code being contributed as part of Open Source and Standardization • Java. FX source code being contributed as part of Open. JFX http: //openjdk. java. net/projects/openjfx/ – Source code being contributed in phases – Initial phase: UI Controls • Oracle is committed to standardize Java. FX through JCP – One or more JSRs will be submitted – Expected to be become part of the Java SE specification

Distribution and Support • Java. FX Distribution – Java. FX Runtime can now be Distribution and Support • Java. FX Distribution – Java. FX Runtime can now be distributed with third party applications – Applies to Java. FX 2. 0. 2 and higher • Java. FX Platform Commercial Support – Java. FX is now part of the Java SE technologies covered through Oracle Premier Support – Applies to Java. FX 2. 0. 2 and higher

Let’s Compare: Java. FX 1. x import javafx. application. *; import javafx. scene. shape. Let’s Compare: Java. FX 1. x import javafx. application. *; import javafx. scene. shape. *; import javafx. scene. paint. *; Stage { scene: Scene{ Content: [ Circle { center. X: 50 center. Y: 50 radius: 50 fill: Color. RED } ] } }

Let’s Compare: Java. FX 2. 0 public class Java. FXTest extends Application { @Override Let’s Compare: Java. FX 2. 0 public class Java. FXTest extends Application { @Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 100); stage. set. Scene(scene); Circle c 1 = new Circle(50. 0 f, Color. RED); root. get. Children(). add(c 1); stage. set. Visible(true); } public static void main(String a[]) { Launcher. launch(Java. FXTest. class, null); } }

Let’s Compare: FXML <Border. Pane> <center> <Circle radius=“ 50” center. X=“ 50” center. Y=“ Let’s Compare: FXML

public class Java. FXTest extends Application { @Override public void start(Stage stage) { stage. set. Title(“FXML Example”); Parent root = FXMLLoader. load(get. Class(). get. Resource(“example. fxml"), Resource. Bundle. get. Bundle(“r. fxml_example")); stage. set. Scene(new Scene(root)); stage. show(); } }

Scene Graph • Directed Acyclic Graph • Parents and children • Representation of the Scene Graph • Directed Acyclic Graph • Parents and children • Representation of the GUI components

23 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection 23 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Media • Java. FX supports both visual and audio media • Cross-platform Java. FX Media • Java. FX supports both visual and audio media • Cross-platform Java. FX media file format (fxm, mp 3) – Platform specific formats supported via native players • Media class represents a media file • Media. Player provides control of the media rendering • Media. View uses Media. Player to render media as Node – Many Media. Views can use the same Media. Player (cheaply)

Adding HTML Content The Embedded Browser • Web. Engine – Provides basic web page Adding HTML Content The Embedded Browser • Web. Engine – Provides basic web page browsing functionality – Supports user interaction: navigating links, submitting forms • Web. View – Web page as a Node in scenegraph • Effects can be applied – Encapsulates Web. Engine object – No plugin support

Charts http: //download. oracle. com/otndocs/products/javafx/2/samples/Ensemble/index. html Charts http: //download. oracle. com/otndocs/products/javafx/2/samples/Ensemble/index. html

Effects. . . Gaussian. Blur Inner. Shadow Reflection Sepia. Tone Effects. . . Gaussian. Blur Inner. Shadow Reflection Sepia. Tone

Transforms Rectangle rect=new Rectangle(0, 0, 60); rect. set. Fill(Color. DODGERBLUE); rect. set. Arc. Width(10); Transforms Rectangle rect=new Rectangle(0, 0, 60); rect. set. Fill(Color. DODGERBLUE); rect. set. Arc. Width(10); rect. set. Arc. Height(10); rect. set. Rotate(45); rect. set. Scale. X(2); rect. set. Scale. Y(0. 5); Shear shear = new Shear(0. 7, 0); rect. get. Transforms(). add(shear); rect. set. Translate. X(40); rect. set. Translate. Y(10);

Binding • Creates a dependency between a property and a changeable value • High Binding • Creates a dependency between a property and a changeable value • High level API – Easy to use – Covers most common situations • Low level API – Allows for more complex interactions – Optimised for fast execution and small footprint

Properties • Basis for high level binding API • Concrete types for all primitives, Properties • Basis for high level binding API • Concrete types for all primitives, String and Object – Double. Property, String. Property, etc • Simple API – bind / unbind – bind. Bidirectional / unbind. Bidirectional – is. Bound

Simple Binding Example private Simple. Double. Property top. XProperty = new Simple. Double. Property(); Simple Binding Example private Simple. Double. Property top. XProperty = new Simple. Double. Property(); private Simple. Double. Property top. YProperty = new Simple. Double. Property(); Line fold. Line = new Line(); fold. Line. set. End. X(200); fold. Line. set. End. Y(200); fold. Line. start. XProperty(). bind(top. XProperty); fold. Line. start. YProperty(). bind(top. YProperty); . . . top. XProperty. set(tx); top. YProperty. set(ty);

Timeline Based Animations • Timeline – Modifies values of variables specified in Key. Frames Timeline Based Animations • Timeline – Modifies values of variables specified in Key. Frames • Key. Frame: specifies that a variable should have – A particular value at a particular time • Key. Value: Value to be interpolated for an interval

Animated Transitions • Pre-defined, single-purpose animations – Fade, Path, Pause, Rotate, Scale, Translate – Animated Transitions • Pre-defined, single-purpose animations – Fade, Path, Pause, Rotate, Scale, Translate – Can specify to, from and by values • Container transitions – Parallel, sequential – Can be nested arbitarily • Transitions and Timelines share ancestary – A Timeline can be added to a Parallel / Sequential transition

Standard Java Tools for Easy Development • Source editor with improved syntactic highlighting, code Standard Java Tools for Easy Development • Source editor with improved syntactic highlighting, code completion, refactoring etc. • Full debugger and profiler support • Project wizard for easy creation of Java. FX applications Other Java IDEs • Source editor with syntactic highlighting, code completion, refactoring etc. • Full debugger and Profiler support

Java. FX Scene Builder for Rapid UI Design • WYSIWYG GUI design tool for Java. FX Scene Builder for Rapid UI Design • WYSIWYG GUI design tool for the Java. FX platform • Enables designing user interface screens by simply dragging and positioning GUI components from a palette onto a scene • Generates files in FXML format that can be used within a project in any IDE such as Net. Beans or Eclipse • Can be used to create GUI for desktop and Web applications • Currently in Early Access (by invitation)

Java. FX Future Directions Oracle’s Next Generation Java Client Solution • Tighter Integration with Java. FX Future Directions Oracle’s Next Generation Java Client Solution • Tighter Integration with Java SE • Migration Path for Java Client UI Technologies • Optimized Web Services Support • Advanced Tooling • Support for Modern Device Interactions • Delivering on the Cross Platform Promise

Java. FX is … • Cross platform: Windows GA, Mac & Linux Dev. Preview Java. FX is … • Cross platform: Windows GA, Mac & Linux Dev. Preview • Familiar: 100% Java APIs • Powerful: leverages underlying Java platform • Modern: CSS skinning, HW acceleration, Webkit • Backwards ‘compatible’: Swing & SWT interoperability • Flexible: applicable to embedded, tablets and mobile • Open Source: http: //openjdk. java. net/projects/openjfx

Java. FX Roadmap Java. FX 3. 0 Java. FX 2. 1 • Windows GA Java. FX Roadmap Java. FX 3. 0 Java. FX 2. 1 • Windows GA • Mac OS X Dev. Preview • Mac OS X GA • Linux Dev. Preview 2011 2012 • Included in JDK 8 • Concurrent OS support (Windows, Mac OS, Linux) 2013 Java. FX 2. 0. 2 Java. FX 2. 2 • JDK 7 co-install 2014 • Linux GA Java. FX Scene Builder EA Java. FX Scene Builder GA Net. Beans 7. 1 Net. Beans • Java. FX 2. 0 Support • Java. FX 3. 0 Support

Resources • Java. FX website: http: //javafx. com • Open source project http: //openjdk. Resources • Java. FX website: http: //javafx. com • Open source project http: //openjdk. java. net/projects/openjfx/ • Oracle Premier Support for Software http: //www. oracle. com/us/support/software/premier/ • Blogs – http: //fxexperience. com – http: //blogs. oracle. com/javafx • Twitter: @javafx 4 you

The preceding is intended to outline our general product direction. It is intended for The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Node Parent (abstract) Group Region Control Group effects and transforms to be applied to Node Parent (abstract) Group Region Control Group effects and transforms to be applied to a collection of child nodes. Will not resize Region class for nodes that can be styled with CSS and layout children. Will resize auto Control class for high-level skinnable nodes designed for user interaction. Tab. Sample project 41 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Bindings Binding one GUI component to another btn. pref. Width. Property(). bind(scene. width. Property()); Bindings Binding one GUI component to another btn. pref. Width. Property(). bind(scene. width. Property()); (Tabs. Sample) Binding GUI component to Worker (Times. Controller. Task) lbl. Status. text. Property(). bind(get. Reviews. Task. message. Property()); btn. Go. disable. Property(). bind(get. Reviews. Task. running. Property()); lst. View. items. Property(). bind(get. Reviews. Task. value. Property()); Define your own Thread-Safe properties and listen for changes (Threads. Controller) service. get. Counter. Property(). add. Listener(new Change. Listener(){ @Override public void changed(Observable. Value o, Object old. Val, Object new. Val){ System. out. println("Counter changed to: " + service. get. Counter()); } }); 42 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Communicate between Main and Controller FXMLLoader loader = new FXMLLoader(get. Class(). get. Resource( Communicate between Main and Controller FXMLLoader loader = new FXMLLoader(get. Class(). get. Resource("/fxml/Threads. fxml")); Parent root = (Parent) loader. load(); Threads. Controller controller = loader. get. Controller(); controller. set. Stage(primary. Stage); In Your. Controller, you need this method: public void set. Stage(Stage stage) { this. primary. Stage = stage; } 43 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Concurrency in java. FX The javafx. concurrent package consists of the Worker interface and Concurrency in java. FX The javafx. concurrent package consists of the Worker interface and two concrete implementations, Task and Service classes. The Worker interface provides APIs that are useful for a background worker to communicate with the UI. The Task class is a fully observable implementation of the java. util. concurrent. Future. Task class. The Task class enables developers to implement asynchronous tasks in Java. FX applications. The Task class defines a one-time object that cannot be reused. The Service class executes tasks. If you need a reusable Worker object, use the Service class. 44 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Worker (Interface) Task Service Group effects and transforms to be applied to a collection Worker (Interface) Task Service Group effects and transforms to be applied to a collection of child nodes. Region class for nodes that can be styled with CSS and layout children. Control class for high-level skinnable nodes designed for user interaction. 45 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Inside the call method, you can use: update. Progress(), update. Message() , update. Title() Inside the call method, you can use: update. Progress(), update. Message() , update. Title() methods, which update the values of the corresponding properties on the Java. FX Application thread. 46 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Web Services http: //www. programmableweb. com/ http: //www. faroo. com/hp/api. html http: //www. faroo. Web Services http: //www. programmableweb. com/ http: //www. faroo. com/hp/api. html http: //www. faroo. com/api? q=iphone&start=1&length=10&l=e n&src=web&f=json http: //jsonviewer. stack. hu/

What is Java. FX? It’s a language for creating graphical user interfaces. . . What is Java. FX? It’s a language for creating graphical user interfaces. . .

What is Java. FX? It’s a language for creating graphical user interfaces. . . What is Java. FX? It’s a language for creating graphical user interfaces. . .

Regions: Slider Regions: Slider

So, who wants to learn more? So, who wants to learn more?

Public/private constants lec 08. blackjack. Card. Store as little as possible in an instance. Public/private constants lec 08. blackjack. Card. Store as little as possible in an instance. polymorphism lec 03. simplepoly

how to inspect a class' hierarchy cntrl-H, cntrl-shift-alt-u Reflection lab 08. reflection using the how to inspect a class' hierarchy cntrl-H, cntrl-shift-alt-u Reflection lab 08. reflection using the debugger lec 08 debugger recursion and videos