├── .idea
├── .name
├── gradle.xml
├── copyright
│ └── profiles_settings.xml
├── scopes
│ └── scope_settings.xml
├── ant.xml
├── encodings.xml
├── vcs.xml
├── description.html
├── modules.xml
├── artifacts
│ └── JavaFXApp.xml
├── misc.xml
└── compiler.xml
├── hello
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── HelloWorld.java
│ └── solutions
│ │ └── BigHello.java
└── hello.iml
├── .gitignore
├── Chapter3
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── PetMaster.java
│ ├── VideoGame.java
│ ├── Fish.java
│ ├── PlayStation4.java
│ ├── Pet.java
│ └── CreatePlayStation4Objects.java
└── Chapter3.iml
├── Chapter4
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── compiler.xml
│ └── misc.xml
├── src
│ ├── PetMaster.java
│ ├── DoWhileDemo.java
│ ├── Pet.java
│ ├── BonusPoints.java
│ ├── solutions
│ │ ├── TemperatureConverter.java
│ │ └── TemperatureConverter2.java
│ ├── Fish.java
│ ├── GradeInterpreter.java
│ └── ReportCard.java
└── Chapter4.iml
├── Chapter5
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── pets
│ │ ├── Talkative.java
│ │ ├── Cat.java
│ │ ├── Parrot.java
│ │ ├── Fish.java
│ │ ├── Dog.java
│ │ ├── PetMaster.java
│ │ └── Swimmable.java
│ ├── solutions
│ │ ├── pets
│ │ │ ├── Talkative.java
│ │ │ ├── Pet.java
│ │ │ ├── PetMaster.java
│ │ │ ├── Fish.java
│ │ │ ├── Dog.java
│ │ │ └── Swimmable.java
│ │ └── lambdapets
│ │ │ ├── Talkative.java
│ │ │ ├── Pet.java
│ │ │ └── PetMasterLambda.java
│ ├── mylambdas
│ │ ├── Talkative.java
│ │ ├── Pet.java
│ │ └── PetMasterLambda.java
│ ├── calc
│ │ ├── ArithmeticOperation.java
│ │ ├── Calculator.java
│ │ ├── CalculatorWithLambdas.java
│ │ └── CalculatorWithAnonymousClasses.java
│ └── abstractclasses
│ │ ├── Dog.java
│ │ └── Animal.java
└── Chapter5.iml
├── Chapter6
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── friends
│ │ ├── ContactDetail.java
│ │ ├── HashTableBrokenDemo.java
│ │ ├── HashTableGenericsDemo.java
│ │ └── HashTableDemo.java
│ ├── CarMaster.java
│ ├── pets
│ │ ├── Fish.java
│ │ └── FishTank.java
│ ├── ArrayListDemo.java
│ ├── solutions
│ │ ├── MyContacts.java
│ │ └── ContactDetail.java
│ └── vehicles
│ │ └── Car.java
└── Chapter6.iml
├── HelloPet
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ └── compiler.xml
└── MyPet.iml
├── Chapter11
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ └── compiler.xml
├── abc.dat
├── src
│ ├── iosamples
│ │ ├── abc.dat
│ │ ├── MyByteReader.java
│ │ ├── MyByteWriter.java
│ │ └── MyBufferedByteReader.java
│ ├── PrintArguments.java
│ ├── solution
│ │ ├── Score.java
│ │ └── ScoreManager.java
│ ├── serialization
│ │ ├── GameState.java
│ │ └── GameStateManager.java
│ └── niosamples
│ │ ├── FileCopy.java
│ │ ├── MyTextFileWriter.java
│ │ ├── MyTextFileReader.java
│ │ └── MyTextFileBufferedFileWriter.java
├── data
│ └── scores.txt
└── Chapter11.iml
├── Chapter12
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ └── compiler.xml
├── Chapter12.iml
└── src
│ ├── WebSiteReader.java
│ └── FileDownload.java
├── Chapter8_bad
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── Chapter8.iml
│ ├── misc.xml
│ └── compiler.xml
├── Calculator
│ ├── .idea
│ │ ├── ant.xml
│ │ ├── gradle.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── scopes
│ │ │ └── scope_settings.xml
│ │ ├── encodings.xml
│ │ ├── vcs.xml
│ │ ├── description.html
│ │ ├── modules.xml
│ │ ├── artifacts
│ │ │ └── JavaFXApp.xml
│ │ ├── misc.xml
│ │ └── compiler.xml
│ ├── src
│ │ └── mycalculator
│ │ │ ├── Controller.java
│ │ │ └── Main.java
│ └── Calculator.iml
└── Signin
│ ├── .idea
│ ├── ant.xml
│ ├── gradle.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── description.html
│ ├── modules.xml
│ ├── artifacts
│ │ └── JavaFXApp.xml
│ ├── misc.xml
│ └── compiler.xml
│ ├── Signin.iml
│ └── src
│ ├── signin
│ ├── signin.css
│ ├── BasicController.java
│ ├── Controller.java
│ ├── MainWithBinding.java
│ ├── Main.java
│ ├── BindingController.java
│ ├── signin.fxml
│ ├── signin_for_binding_sample.fxml
│ ├── MainPureJava.java
│ └── ControllerLongRunningThread.java
│ └── treads
│ ├── SingleThreadedDemo.java
│ └── MultiThreadedDemo.java
├── Chapter8
├── .idea
│ ├── ant.xml
│ ├── gradle.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── description.html
│ ├── modules.xml
│ ├── artifacts
│ │ └── JavaFXApp.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── mycalculator
│ │ ├── Controller.java
│ │ └── Main.java
│ ├── signin
│ │ ├── signin.css
│ │ ├── BasicController.java
│ │ ├── Controller.java
│ │ ├── MainWithBinding.java
│ │ ├── Main.java
│ │ ├── BindingController.java
│ │ ├── signin.fxml
│ │ ├── signin_for_binding_sample.fxml
│ │ ├── MainPureJava.java
│ │ └── ControllerLongRunningThread.java
│ └── treads
│ │ ├── SingleThreadedDemo.java
│ │ └── MultiThreadedDemo.java
└── Chapter8.iml
├── PingPong
├── .idea
│ ├── ant.xml
│ ├── gradle.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── description.html
│ ├── modules.xml
│ ├── artifacts
│ │ └── JavaFXApp.xml
│ ├── misc.xml
│ └── compiler.xml
├── src
│ ├── enumSamples
│ │ ├── Day.java
│ │ ├── GameConstants.java
│ │ └── GreetTheDay.java
│ └── pong
│ │ ├── PingPongController_v1.java
│ │ ├── PingPong.java
│ │ ├── pingpong.fxml
│ │ ├── PingPongController_v2.java
│ │ ├── PingPongController_v3.java
│ │ ├── PingPongController_v4.java
│ │ ├── PingPongController_v5.java
│ │ └── PingPongController_v6.java
└── PingPong.iml
├── src
└── sample
│ ├── Controller.java
│ ├── sample.fxml
│ └── Main.java
├── TicTacToe
├── .idea
│ ├── ant.xml
│ ├── gradle.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── description.html
│ ├── modules.xml
│ ├── artifacts
│ │ └── JavaFXApp.xml
│ ├── misc.xml
│ └── compiler.xml
├── TicTacToe.iml
└── src
│ └── mygame
│ ├── tictactoe.css
│ ├── TicTacToe.java
│ └── tictactoe.fxml
├── Chapter7
├── Signin
│ ├── src
│ │ └── signin
│ │ │ ├── Controller.java
│ │ │ ├── signin.css
│ │ │ ├── Main.java
│ │ │ └── signin.fxml
│ ├── .idea
│ │ ├── ant.xml
│ │ ├── gradle.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── scopes
│ │ │ └── scope_settings.xml
│ │ ├── encodings.xml
│ │ ├── vcs.xml
│ │ ├── description.html
│ │ ├── modules.xml
│ │ ├── artifacts
│ │ │ └── JavaFXApp.xml
│ │ ├── misc.xml
│ │ └── compiler.xml
│ └── Signin.iml
├── sample
│ ├── src
│ │ └── sample
│ │ │ ├── Controller.java
│ │ │ ├── Main.java
│ │ │ └── sample.fxml
│ ├── .idea
│ │ ├── ant.xml
│ │ ├── gradle.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── scopes
│ │ │ └── scope_settings.xml
│ │ ├── encodings.xml
│ │ ├── vcs.xml
│ │ ├── description.html
│ │ ├── modules.xml
│ │ ├── artifacts
│ │ │ └── JavaFXApp.xml
│ │ ├── misc.xml
│ │ └── compiler.xml
│ └── Chapter7.iml
├── Calculator
│ ├── .idea
│ │ ├── ant.xml
│ │ ├── gradle.xml
│ │ ├── copyright
│ │ │ └── profiles_settings.xml
│ │ ├── scopes
│ │ │ └── scope_settings.xml
│ │ ├── encodings.xml
│ │ ├── vcs.xml
│ │ ├── description.html
│ │ ├── modules.xml
│ │ ├── artifacts
│ │ │ └── JavaFXApp.xml
│ │ ├── misc.xml
│ │ └── compiler.xml
│ ├── src
│ │ └── mycalculator
│ │ │ ├── Controller.java
│ │ │ └── Main.java
│ └── Calculator.iml
└── .idea
│ ├── copyright
│ └── profiles_settings.xml
│ ├── scopes
│ └── scope_settings.xml
│ ├── encodings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── misc.xml
│ ├── artifacts
│ └── JavaFXApp.xml
│ └── compiler.xml
├── Signin
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── scopes
│ │ └── scope_settings.xml
│ └── artifacts
│ │ └── JavaFXApp.xml
└── Signin.iml
└── jfk.iml
/.idea/.name:
--------------------------------------------------------------------------------
1 | jfk
--------------------------------------------------------------------------------
/hello/.idea/.name:
--------------------------------------------------------------------------------
1 | hello
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | out
--------------------------------------------------------------------------------
/Chapter3/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter3
--------------------------------------------------------------------------------
/Chapter4/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter4
--------------------------------------------------------------------------------
/Chapter5/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter5
--------------------------------------------------------------------------------
/Chapter6/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter6
--------------------------------------------------------------------------------
/HelloPet/.idea/.name:
--------------------------------------------------------------------------------
1 | HelloPet
--------------------------------------------------------------------------------
/Chapter11/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter11
--------------------------------------------------------------------------------
/Chapter12/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter12
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/.name:
--------------------------------------------------------------------------------
1 | Chapter8
--------------------------------------------------------------------------------
/Chapter11/abc.dat:
--------------------------------------------------------------------------------
1 | This is a test file
--------------------------------------------------------------------------------
/Chapter11/src/iosamples/abc.dat:
--------------------------------------------------------------------------------
1 | This is a test file
--------------------------------------------------------------------------------
/Chapter11/data/scores.txt:
--------------------------------------------------------------------------------
1 | My game score is 28000 2015-01-11T16:24:36.324
2 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Chapter8/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PingPong/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/sample/Controller.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter8/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PingPong/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Chapter7/Signin/src/signin/Controller.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter7/sample/src/sample/Controller.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter8/src/mycalculator/Controller.java:
--------------------------------------------------------------------------------
1 | package mycalculator;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/src/mycalculator/Controller.java:
--------------------------------------------------------------------------------
1 | package mycalculator;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/src/mycalculator/Controller.java:
--------------------------------------------------------------------------------
1 | package mycalculator;
2 |
3 | public class Controller {
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter3/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter4/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter5/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter6/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter7/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter8/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/HelloPet/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/PingPong/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Signin/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/hello/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter11/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter12/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Talkative.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public interface Talkative {
7 | public void talk();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Signin/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/hello/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter11/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter12/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter3/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter4/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter5/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter6/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter7/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter8/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/HelloPet/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/PingPong/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/ant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter11/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter11/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter12/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter12/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/Talkative.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public interface Talkative {
7 | public void talk();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/hello/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/hello/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter3/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter3/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter4/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter4/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter5/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter5/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter5/src/mylambdas/Talkative.java:
--------------------------------------------------------------------------------
1 | package mylambdas;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public interface Talkative {
7 | public String talk(String petName);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter6/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter6/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter7/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter8/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloPet/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HelloPet/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PingPong/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/PingPong/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PingPong/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
2 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/lambdapets/Talkative.java:
--------------------------------------------------------------------------------
1 | package solutions.lambdapets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public interface Talkative {
7 | public String talk(String petName);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/PingPong/src/enumSamples/Day.java:
--------------------------------------------------------------------------------
1 | package enumSamples;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public enum Day {
7 | SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
8 | THURSDAY, FRIDAY, SATURDAY
9 | }
10 |
--------------------------------------------------------------------------------
/hello/src/HelloWorld.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class HelloWorld {
5 |
6 | public static void main(String[] args){
7 | System.out.println("HelloWorld!");
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Cat.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public class Cat implements Talkative {
7 | public void talk(){
8 | System.out.println("Meow! Meow!");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter5/src/calc/ArithmeticOperation.java:
--------------------------------------------------------------------------------
1 | package calc;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public interface ArithmeticOperation {
7 |
8 | public double performOperation(double first, double second);
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Parrot.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public class Parrot implements Talkative {
7 | public void talk(){
8 | System.out.println("My name is Kesha.");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter6/src/friends/ContactDetail.java:
--------------------------------------------------------------------------------
1 | package friends;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class ContactDetail {
7 | String fullName;
8 | String facebookID;
9 | String phone;
10 | String email;
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter5/src/abstractclasses/Dog.java:
--------------------------------------------------------------------------------
1 | package abstractclasses;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Dog extends Animal{
7 | public void talk(){
8 |
9 | System.out.println("Bark! Bark-bark!");
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter11/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter12/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PingPong/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/Pet.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | import solutions.lambdapets.Talkative;
4 |
5 | /**
6 | * Created by NewProgrammer on 3/28/15.
7 | */
8 | public class Pet {
9 |
10 | String name;
11 |
12 | Pet(String name){
13 | this.name = name;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/hello/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/HelloPet/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter3/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter4/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter5/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter6/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/sample/sample.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/HelloPet/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Fish.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public class Fish implements Swimmable {
7 | public void swim(int howFar){
8 | System.out.println("OK, will swim " + howFar + " feet");
9 | }
10 | public void dive(int howDeep){
11 | System.out.println("OK, will dive " + howDeep + " feet");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Dog.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by yfain11 on 8/13/14.
5 | */
6 | public class Dog implements Talkative, Swimmable {
7 | public void talk(){
8 | System.out.println("Bark! Bark-bark!");
9 | }
10 |
11 | public void swim(int howFar){
12 | System.out.println("Will swim about a half of this distance: " + howFar/2 + " feet");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/Chapter8.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter6/src/CarMaster.java:
--------------------------------------------------------------------------------
1 | import vehicles.Car;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class CarMaster {
7 | public static void main(String[] args) {
8 |
9 | Car myCar = new Car();
10 |
11 | Object myOtherCar = new Car();
12 |
13 | Car myOtherCarAfterCasting = (Car) myOtherCar;
14 |
15 | // myOtherCarAfterCasting.
16 |
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter11/src/PrintArguments.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class PrintArguments {
5 |
6 | public static void main(String[] args) {
7 |
8 | // How many arguments we've got?
9 | int numberOfArgs = args.length;
10 |
11 | for (int i=0; i
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Chapter6/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Chapter3/src/PetMaster.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class PetMaster {
5 |
6 | public static void main(String[] args) {
7 |
8 | String petReaction;
9 |
10 | Pet myPet = new Pet();
11 |
12 | myPet.eat();
13 |
14 | petReaction = myPet.talk("Tweet!! Tweet!!");
15 |
16 | System.out.println(petReaction);
17 |
18 | myPet.sleep();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter4/src/PetMaster.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class PetMaster {
5 |
6 | public static void main(String[] args) {
7 |
8 | String petReaction;
9 |
10 | Pet myPet = new Pet();
11 |
12 | myPet.eat();
13 |
14 | petReaction = myPet.talk("Tweet!! Tweet!!");
15 |
16 | System.out.println(petReaction);
17 |
18 | myPet.sleep();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/PetMaster.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class PetMaster {
7 | public static void main(String[] args) {
8 |
9 | Dog myDog = new Dog();
10 | myDog.talk();
11 | myDog.swim(7);
12 | myDog.dive(2);
13 |
14 | Fish myFish = new Fish();
15 | myFish.swim(50);
16 | myFish.dive(20);
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter7/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter3/src/VideoGame.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | class VideoGame {
5 |
6 | String color;
7 | int price;
8 |
9 | void start () {
10 | // The code to start the game goes here
11 | }
12 |
13 | void stop () {
14 | // The code to stop the game goes here
15 | }
16 |
17 | void saveScore(String playerName, int score) {
18 | // The code to save score goes here
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/lambdapets/Pet.java:
--------------------------------------------------------------------------------
1 | package solutions.lambdapets;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Pet {
7 |
8 | String name;
9 | Talkative myTalkingRules;
10 |
11 | Pet(Talkative talkRules, String name){
12 | this.name = name;
13 | myTalkingRules = talkRules;
14 | }
15 |
16 | public String speakup(){
17 |
18 | return myTalkingRules.talk(name);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/PetMaster.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class PetMaster {
7 | public static void main(String[] args) {
8 |
9 | Dog myDog = new Dog("Sammy");
10 | myDog.talk();
11 | myDog.swim(7);
12 | myDog.dive(2);
13 |
14 | Fish myFish = new Fish("Mary");
15 | myFish.swim(50);
16 | myFish.dive(20);
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/jfk.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter11/Chapter11.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chapter12/Chapter12.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/PingPong/src/enumSamples/GameConstants.java:
--------------------------------------------------------------------------------
1 | package enumSamples;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public enum GameConstants {
7 |
8 | TABLE_WIDTH(320),TABLE_HEIGHT(220), KID_RACKET_Y_START(100),
9 | KID_RACKET_X_START(300),TABLE_TOP(12), TABLE_BOTTOM(180),RACKET_INCREMENT(4);
10 |
11 | private int value;
12 |
13 | private GameConstants(int value){
14 | this.value=value;
15 | };
16 |
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v1.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.scene.input.KeyCode;
4 | import javafx.scene.input.KeyEvent;
5 |
6 | // This version of the controller just prints the code of the pressed key on the console
7 |
8 | public class PingPongController_v1 {
9 |
10 | public void keyReleasedHandler(KeyEvent event){
11 |
12 | KeyCode keyCode = event.getCode();
13 | System.out.println("You pressed " + keyCode);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Signin/Signin.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/hello/hello.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter3/Chapter3.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter4/Chapter4.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter5/Chapter5.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter6/Chapter6.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter8/Chapter8.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/HelloPet/MyPet.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/PingPong/PingPong.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter3/src/Fish.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class Fish extends Pet {
5 |
6 | int currentDepth=0;
7 |
8 | public int dive(int howDeep){
9 |
10 | currentDepth=currentDepth + howDeep;
11 | System.out.println("Diving for " +
12 | howDeep + " feet");
13 | System.out.println("I'm at " + currentDepth +
14 | " feet below sea level");
15 |
16 | return currentDepth;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter5/src/abstractclasses/Animal.java:
--------------------------------------------------------------------------------
1 | package abstractclasses;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public abstract class Animal {
7 |
8 | String animalClass;
9 | String name;
10 |
11 | public void setName(String name){
12 | this.name = name;
13 | }
14 |
15 | public void sleep(){
16 | System.out.println("The " + name + " is tired and goes to sleep.");
17 | }
18 |
19 | abstract public void talk();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter7/Signin/Signin.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/TicTacToe/TicTacToe.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/TicTacToe/src/mygame/tictactoe.css:
--------------------------------------------------------------------------------
1 | .button{
2 | -fx-focus-color: transparent;
3 | -fx-background-insets: -1, 0, 1, 1;
4 |
5 | -fx-font-weight: bold;
6 | -fx-font-size: 36;
7 | -fx-text-fill: blue;
8 | -fx-background-color: violet;
9 | -fx-border-color:darkblue;
10 | }
11 |
12 | .menu-bar{
13 | -fx-background-color: gold;
14 | }
15 |
16 | .winning-square {
17 | -fx-background-color: radial-gradient( radius 100%, white, lightyellow, lawngreen);
18 | -fx-text-fill: red;
19 | }
--------------------------------------------------------------------------------
/Chapter7/sample/Chapter7.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/signin.css:
--------------------------------------------------------------------------------
1 | #submitBtn{
2 | -fx-background-color: lightskyblue;
3 | -fx-font-family:verdana;
4 | -fx-font-size:20;
5 | -fx-font-weight: bold;
6 | -fx-stroke:navy;
7 | -fx-font-style:italic;
8 | -fx-border-radius: 20;
9 | -fx-background-radius: 20;
10 | -fx-padding: 5;
11 | }
12 |
13 | .label{
14 | -fx-text-fill: red;
15 | }
16 |
17 | .bluelabel{
18 | -fx-text-fill: blue;
19 | -fx-font-family:verdana;
20 | -fx-font-style:italic;
21 | }
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/Signin.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/Calculator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter7/Signin/src/signin/signin.css:
--------------------------------------------------------------------------------
1 | #submitBtn{
2 | -fx-background-color: lightskyblue;
3 | -fx-font-family:verdana;
4 | -fx-font-size:20;
5 | -fx-font-weight: bold;
6 | -fx-stroke:navy;
7 | -fx-font-style:italic;
8 | -fx-border-radius: 20;
9 | -fx-background-radius: 20;
10 | -fx-padding: 5;
11 | }
12 |
13 | .label{
14 | -fx-text-fill: red;
15 | }
16 |
17 | .bluelabel{
18 | -fx-text-fill: blue;
19 | -fx-font-family:verdana;
20 | -fx-font-style:italic;
21 | }
--------------------------------------------------------------------------------
/Chapter8/src/treads/SingleThreadedDemo.java:
--------------------------------------------------------------------------------
1 | package treads;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class SingleThreadedDemo {
7 | public static void main(String[] args) {
8 |
9 | for (int i=0; i<5;i++){
10 | System.out.println("The value of i in power of 4 is " + i*i*i*i*i);
11 | }
12 |
13 | for (int k=0; k<5;k++){
14 | System.out.println("*** The value of k is " + k + "!");
15 | }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter5/src/mylambdas/Pet.java:
--------------------------------------------------------------------------------
1 | package mylambdas;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Pet {
7 |
8 |
9 | // Arguments: rules for talking and pet's name
10 | // Return: What did the pet say
11 | public String speakup(Talkative talkRules, String name){
12 | return talkRules.talk(name);
13 | }
14 |
15 | static public String saySomething(Talkative talkRules, String name){
16 | return talkRules.talk(name);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/Calculator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/signin.css:
--------------------------------------------------------------------------------
1 | #submitBtn{
2 | -fx-background-color: lightskyblue;
3 | -fx-font-family:verdana;
4 | -fx-font-size:20;
5 | -fx-font-weight: bold;
6 | -fx-stroke:navy;
7 | -fx-font-style:italic;
8 | -fx-border-radius: 20;
9 | -fx-background-radius: 20;
10 | -fx-padding: 5;
11 | }
12 |
13 | .label{
14 | -fx-text-fill: red;
15 | }
16 |
17 | .bluelabel{
18 | -fx-text-fill: blue;
19 | -fx-font-family:verdana;
20 | -fx-font-style:italic;
21 | }
--------------------------------------------------------------------------------
/Chapter8/src/signin/BasicController.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.event.ActionEvent;
4 | import javafx.scene.input.MouseEvent;
5 |
6 |
7 | public class BasicController {
8 |
9 | public void signInClicked(ActionEvent evt){
10 |
11 | System.out.println("Hello from signInClicked method in controller");
12 | }
13 |
14 | public void signInMouseClicked(MouseEvent evt){
15 |
16 | System.out.println("Hello from signInMouseClicked method in controller");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/treads/SingleThreadedDemo.java:
--------------------------------------------------------------------------------
1 | package treads;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class SingleThreadedDemo {
7 | public static void main(String[] args) {
8 |
9 | for (int i=0; i<5;i++){
10 | System.out.println("The value of i in power of 4 is " + i*i*i*i*i);
11 | }
12 |
13 | for (int k=0; k<5;k++){
14 | System.out.println("*** The value of k is " + k + "!");
15 | }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter7/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/BasicController.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.event.ActionEvent;
4 | import javafx.scene.input.MouseEvent;
5 |
6 |
7 | public class BasicController {
8 |
9 | public void signInClicked(ActionEvent evt){
10 |
11 | System.out.println("Hello from signInClicked method in controller");
12 | }
13 |
14 | public void signInMouseClicked(MouseEvent evt){
15 |
16 | System.out.println("Hello from signInMouseClicked method in controller");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/hello/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter5/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter11/src/solution/Score.java:
--------------------------------------------------------------------------------
1 | package solution;
2 |
3 | import java.io.Serializable;
4 | import java.time.LocalDateTime;
5 |
6 | class Score implements Serializable {
7 | String name;
8 | int score;
9 | LocalDateTime dateTime;
10 |
11 | Score(String name, int score, LocalDateTime dateTime){
12 | this.name=name;
13 | this.score=score;
14 | this.dateTime=dateTime;
15 | }
16 |
17 | public String toString(){
18 | return name + " scored " + score + " on " + dateTime;
19 | }
20 | }
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/Fish.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | import pets.Swimmable;
4 |
5 | /**
6 | * Created by yfain11 on 8/13/14.
7 | */
8 | public class Fish extends Pet implements Swimmable {
9 |
10 | Fish(String name) {
11 | super(name);
12 | }
13 | public void swim(int howFar){
14 | System.out.println("OK," + name + " will swim " + howFar + " feet");
15 | }
16 | public void dive(int howDeep){
17 | System.out.println("OK, " + name + " will dive " + howDeep + " feet");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Signin/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter7/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter8/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/PingPong/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter8/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/PingPong/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/artifacts/JavaFXApp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/JavaFXApp
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter4/src/DoWhileDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class DoWhileDemo {
7 | public static void main(String[] args) {
8 |
9 | String playAgain = "no";
10 |
11 | Scanner usersConsole = new Scanner(System.in);
12 |
13 | do{
14 | System.out.print("Do you want to play again (yes/no)? ");
15 | playAgain = usersConsole.nextLine();
16 |
17 | } while ("yes".equals(playAgain));
18 |
19 | System.out.println("Thank you for playing!");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/Dog.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | import pets.Swimmable;
4 | import pets.Talkative;
5 |
6 | /**
7 | * Created by yfain11 on 8/13/14.
8 | */
9 | public class Dog extends Pet implements Talkative, Swimmable {
10 |
11 | Dog(String name) {
12 | super(name);
13 | }
14 | public void talk(){
15 | System.out.println( "My name is " + name + " Bark-bark-bark!");
16 | }
17 |
18 | public void swim(int howFar){
19 | System.out.println(name + " will swim about a half of this distance: " + howFar/2 + " feet");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Chapter3/src/PlayStation4.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | class PlayStation4 extends VideoGame{
5 |
6 | String hardDiskSize;
7 |
8 | // Some other attributes and methods go here
9 |
10 | void shareOnFacebook(){
11 | // Code to share on Facebook go here
12 | System.out.println("Hey, Facebook, I got PlayStation4 with " + hardDiskSize);
13 | }
14 |
15 | void shareOnTwitter(){
16 | // Code to share on Twitter go here
17 | System.out.println("Hey, Twitter, I got PlayStation4 with " + hardDiskSize);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Chapter3/src/Pet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class Pet {
5 |
6 | int age;
7 | float weight;
8 | float height;
9 | String color;
10 |
11 | public void sleep(){
12 | System.out.println(
13 | "Good night, see you tomorrow!");
14 | }
15 |
16 | public void eat(){
17 | System.out.println(
18 | "I’m so hungry, let me have a snack like nachos!");
19 | }
20 |
21 | public String talk(String aWord){
22 | String petResponse = "OK!! OK!! " +aWord;
23 | return petResponse;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter4/src/Pet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class Pet {
5 |
6 | int age;
7 | float weight;
8 | float height;
9 | String color;
10 |
11 | public void sleep(){
12 | System.out.println(
13 | "Good night, see you tomorrow!");
14 | }
15 |
16 | public void eat(){
17 | System.out.println(
18 | "I’m so hungry, let me have a snack like nachos!");
19 | }
20 |
21 | public String talk(String aWord){
22 | String petResponse = "OK!! OK!! " +aWord;
23 | return petResponse;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter8/src/treads/MultiThreadedDemo.java:
--------------------------------------------------------------------------------
1 | package treads;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class MultiThreadedDemo {
7 | public static void main(String[] args) {
8 |
9 | Thread myThread = new Thread(
10 | () ->{
11 | for (int i=0; i<5;i++){
12 | System.out.println("The value of i in power of 4 is " + i*i*i*i*i);
13 | }
14 | }
15 | );
16 |
17 | myThread.start();
18 |
19 | for (int k=0; k<5;k++){
20 | System.out.println("*** The value of k is " + k + "!");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/hello/src/solutions/BigHello.java:
--------------------------------------------------------------------------------
1 | package solutions;
2 |
3 | /**
4 | * Created by yfain11 on 3/31/14.
5 | */
6 | public class BigHello {
7 |
8 | public static void main(String[] args) {
9 | System.out.println("\n"); // an end of line character to print empty line
10 | System.out.println("* * ***** * * ****");
11 | System.out.println("* * * * * * *");
12 | System.out.println("****** ***** * * * *");
13 | System.out.println("* * * * * * *");
14 | System.out.println("* * ***** ***** ***** **** ");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/treads/MultiThreadedDemo.java:
--------------------------------------------------------------------------------
1 | package treads;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class MultiThreadedDemo {
7 | public static void main(String[] args) {
8 |
9 | Thread myThread = new Thread(
10 | () ->{
11 | for (int i=0; i<5;i++){
12 | System.out.println("The value of i in power of 4 is " + i*i*i*i*i);
13 | }
14 | }
15 | );
16 |
17 | myThread.start();
18 |
19 | for (int k=0; k<5;k++){
20 | System.out.println("*** The value of k is " + k + "!");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter11/src/iosamples/MyByteReader.java:
--------------------------------------------------------------------------------
1 | package iosamples;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.IOException;
5 | public class MyByteReader {
6 |
7 | public static void main(String[] args) {
8 |
9 | try (FileInputStream myFile = new FileInputStream("abc.dat")){
10 |
11 | int byteValue;
12 |
13 | while ((byteValue = myFile.read()) != -1) {
14 |
15 | System.out.print(byteValue + " ");
16 | }
17 | } catch (IOException ioe) {
18 | System.out.println("Could not read file: " +
19 | ioe.getMessage());
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/sample/Main.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class Main extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
14 | primaryStage.setTitle("Hello World");
15 | primaryStage.setScene(new Scene(root, 300, 275));
16 | primaryStage.show();
17 | }
18 |
19 |
20 | public static void main(String[] args) {
21 | launch(args);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter7/sample/src/sample/Main.java:
--------------------------------------------------------------------------------
1 | package sample;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class Main extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
14 | primaryStage.setTitle("Hello World");
15 | primaryStage.setScene(new Scene(root, 300, 275));
16 | primaryStage.show();
17 | }
18 |
19 |
20 | public static void main(String[] args) {
21 | launch(args);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter3/src/CreatePlayStation4Objects.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class CreatePlayStation4Objects {
5 |
6 | public static void main(String[] args) {
7 |
8 | // create one instance of PlayStation4 class
9 | PlayStation4 firstPlayStation = new PlayStation4();
10 | firstPlayStation.hardDiskSize = "500GB";
11 |
12 | // call the method shareOnFacebook
13 | firstPlayStation.shareOnFacebook();
14 |
15 | PlayStation4 secondPlayStation = new PlayStation4();
16 | secondPlayStation.hardDiskSize = "1TB";
17 |
18 | // call the method shareOnTwitter
19 | secondPlayStation.shareOnTwitter();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter6/src/pets/Fish.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Fish {
7 | private float weight;
8 | private String color;
9 |
10 | Fish(float weight, String color){
11 | this.setWeight(weight);
12 | this.setColor(color);
13 | }
14 |
15 | // getters and setters
16 |
17 | public float getWeight() {
18 | return weight;
19 | }
20 |
21 | public void setWeight(float weight) {
22 | this.weight = weight;
23 | }
24 |
25 | public String getColor() {
26 | return color;
27 | }
28 |
29 | public void setColor(String color) {
30 | this.color = color;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Chapter8/src/mycalculator/Main.java:
--------------------------------------------------------------------------------
1 | package mycalculator;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class Main extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("calculator.fxml"));
14 | primaryStage.setTitle("My JavaFX Calculator");
15 | primaryStage.setScene(new Scene(root, 650, 600));
16 | primaryStage.show();
17 | }
18 |
19 |
20 | public static void main(String[] args) {
21 | launch(args);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/PingPong/src/enumSamples/GreetTheDay.java:
--------------------------------------------------------------------------------
1 | package enumSamples;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class GreetTheDay {
7 |
8 | public static void main(String[] args) {
9 |
10 | greet(Day.SATURDAY);
11 | }
12 |
13 | static void greet(Day day){
14 | switch (day) {
15 | case MONDAY:
16 | System.out.println("The week begins");
17 | break;
18 | case SATURDAY:
19 | case SUNDAY:
20 | System.out.println("Hello Weekend!");
21 | break;
22 | default:
23 | System.out.println("Hello Midweek");
24 | break;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/src/mycalculator/Main.java:
--------------------------------------------------------------------------------
1 | package mycalculator;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class Main extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("calculator.fxml"));
14 | primaryStage.setTitle("My JavaFX Calculator");
15 | primaryStage.setScene(new Scene(root, 650, 600));
16 | primaryStage.show();
17 | }
18 |
19 |
20 | public static void main(String[] args) {
21 | launch(args);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 1.8
9 |
10 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chapter4/src/BonusPoints.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class BonusPoints {
5 |
6 | public static void main(String[] args) {
7 |
8 | float totalSpent = getTotalAmount();
9 |
10 | int bonusPoints;
11 |
12 | if (totalSpent > 100){
13 | bonusPoints=Math.round(totalSpent*2);
14 | }
15 | else{
16 | bonusPoints=Math.round(totalSpent);
17 | }
18 |
19 | System.out.println("Today you've earned " + bonusPoints + " points!");
20 | }
21 |
22 | public static float getTotalAmount(){
23 | // This is a dummy code just to illustrate the use of
24 | // if statement in the main method
25 | return 125.90f;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/Chapter6/src/ArrayListDemo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | import java.util.ArrayList;
5 |
6 | public class ArrayListDemo {
7 |
8 | public static void main(String[] args) {
9 | // Create and populate an ArrayList
10 | ArrayList friends = new ArrayList();
11 | friends.add("Mary");
12 | friends.add("Ann");
13 | friends.add("David");
14 | friends.add("Roy");
15 |
16 | // How many friends are there?
17 | int friendsCount = friends.size();
18 |
19 | // Print the content of the ArrayList
20 | for (int i=0; i {
12 | return "I'm a dog. My name is " + name;
13 | };
14 |
15 | Pet myDog = new Pet(dogTalkRules, "Sammy");
16 |
17 | System.out.println(myDog.speakup());
18 |
19 | // parrots
20 | Talkative parrotTalkRules = name -> {
21 | return "I'm a parrot. Don't call me " + name;
22 | };
23 |
24 | Pet myParrot = new Pet(parrotTalkRules, "Charlie");
25 |
26 | System.out.println(myParrot.speakup());
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter11/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Chapter12/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/hello/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter3/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter6/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter7/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter8/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter8_bad/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/HelloPet/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/PingPong/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/TicTacToe/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter5/src/calc/Calculator.java:
--------------------------------------------------------------------------------
1 | package calc;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Calculator {
7 |
8 | static double addTwoNumbers (double first, double second){
9 | double result = first + second;
10 | System.out.println("" + first + " + " +
11 | second + " = " + result );
12 | return result;
13 | }
14 |
15 | static double subtractTwoNumbers (double first, double second){
16 | double result = first - second;
17 | System.out.println("" + first + " - " +
18 | second + " = " + result );
19 | return result;
20 | }
21 |
22 | public static void main(String[] args) {
23 |
24 | addTwoNumbers(3.55, 50.00);
25 | subtractTwoNumbers(3.55, 50.00);
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/Chapter7/Signin/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter7/sample/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter7/Calculator/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter8_bad/Calculator/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter6/src/pets/FishTank.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | import java.util.ArrayList;
7 |
8 | public class FishTank {
9 | public static void main(String[] args) {
10 | ArrayList fishTank = new ArrayList();
11 |
12 | Fish fish1 = new Fish(2.5f, "Red");
13 | Fish fish2 = new Fish(5, "Green");
14 |
15 | Fish theFish;
16 |
17 | fishTank.add(fish1);
18 | fishTank.add(fish2);
19 |
20 | int fishCount = fishTank.size();
21 |
22 | for (int i=0;i 100){
11 | System.out.println("I'm just a little fish and "
12 | + " I can't dive below 100 feet");
13 | currentDepth=currentDepth - howDeep;
14 | }else{
15 | System.out.println("Diving for " + howDeep +
16 | " feet");
17 | System.out.println("I'm at " + currentDepth +
18 | " feet below sea level");
19 | }
20 | return currentDepth;
21 | }
22 |
23 | public String say(String something){
24 | return "Hey, don't you know that fish don't talk?";
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/Chapter5/src/pets/Swimmable.java:
--------------------------------------------------------------------------------
1 | package pets;
2 |
3 | import java.time.LocalDate;
4 | import java.time.Month;
5 |
6 | /**
7 | * Created by NewProgrammer on 3/28/15.
8 | */
9 | public interface Swimmable {
10 |
11 | public void swim(int howFar);
12 |
13 | public default void dive(int howDeep){
14 |
15 | if (isSummer()){
16 | System.out.println("OK, will dive. The water should be warm.");
17 | } else {
18 | System.out.println("Can't dive, sorry. The water's cold for diving.");
19 | }
20 | };
21 |
22 | // Check if it's summer now
23 | static boolean isSummer(){
24 | Month month = LocalDate.now().getMonth();
25 | if (month == Month.JUNE || month == Month.JULY || month == Month.AUGUST){
26 | return true;
27 | } else{
28 | return false;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter4/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Chapter5/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Chapter5/src/solutions/pets/Swimmable.java:
--------------------------------------------------------------------------------
1 | package solutions.pets;
2 |
3 | import java.time.LocalDate;
4 | import java.time.Month;
5 |
6 | /**
7 | * Created by NewProgrammer on 3/28/15.
8 | */
9 | public interface Swimmable {
10 |
11 | public void swim(int howFar);
12 |
13 | public default void dive(int howDeep){
14 |
15 | if (isSummer()){
16 | System.out.println("OK, will dive. The water should be warm.");
17 | } else {
18 | System.out.println("Can't dive, sorry. The water's cold for diving.");
19 | }
20 | };
21 |
22 | // Check if it's summer now
23 | static boolean isSummer(){
24 | Month month = LocalDate.now().getMonth();
25 | if (month == Month.JUNE || month == Month.JULY || month == Month.AUGUST){
26 | return true;
27 | } else{
28 | return false;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/Controller.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.event.ActionEvent;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.PasswordField;
6 | import javafx.scene.control.TextField;
7 |
8 | public class Controller {
9 |
10 | @FXML
11 | private TextField id;
12 |
13 | @FXML
14 | private PasswordField pwd;
15 |
16 | public void signInClicked(ActionEvent evt){
17 |
18 | String userID = id.getText();
19 | String password = pwd.getText();
20 |
21 | if (!"Yakov".equals(userID)){
22 | id.setStyle("-fx-background-color: lightpink;");
23 | } else{
24 | id.setStyle("-fx-background-color: white;");
25 | }
26 |
27 | System.out.println("got id:" + userID + ", got password: " + password);
28 |
29 | System.out.println("Hello from signInClicked method in controller");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TicTacToe/src/mygame/TicTacToe.java:
--------------------------------------------------------------------------------
1 | package mygame;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class TicTacToe extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("tictactoe.fxml"));
14 | primaryStage.setTitle("TicTacToe");
15 | Scene scene = new Scene(root, 300, 325);
16 | scene.getStylesheets().add(getClass()
17 | .getResource("tictactoe.css").toExternalForm());
18 | primaryStage.setResizable(false);
19 | primaryStage.setScene(scene);
20 | primaryStage.show();
21 | }
22 |
23 |
24 | public static void main(String[] args) {
25 | launch(args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/MainWithBinding.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class MainWithBinding extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("signin_for_binding_sample.fxml"));
14 |
15 | primaryStage.setTitle("Sign In");
16 |
17 | Scene scene = new Scene(root, 200, 170);
18 | scene.getStylesheets().add(getClass()
19 | .getResource("signin.css").toExternalForm());
20 |
21 |
22 |
23 | primaryStage.setScene(scene);
24 | primaryStage.show();
25 | }
26 |
27 |
28 | public static void main(String[] args) {
29 | launch(args);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/Controller.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.event.ActionEvent;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.PasswordField;
6 | import javafx.scene.control.TextField;
7 |
8 | public class Controller {
9 |
10 | @FXML
11 | private TextField id;
12 |
13 | @FXML
14 | private PasswordField pwd;
15 |
16 | public void signInClicked(ActionEvent evt){
17 |
18 | String userID = id.getText();
19 | String password = pwd.getText();
20 |
21 | if (!"Yakov".equals(userID)){
22 | id.setStyle("-fx-background-color: lightpink;");
23 | } else{
24 | id.setStyle("-fx-background-color: white;");
25 | }
26 |
27 | System.out.println("got id:" + userID + ", got password: " + password);
28 |
29 | System.out.println("Hello from signInClicked method in controller");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter7/sample/src/sample/sample.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/MainWithBinding.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class MainWithBinding extends Application {
10 |
11 | @Override
12 | public void start(Stage primaryStage) throws Exception{
13 | Parent root = FXMLLoader.load(getClass().getResource("signin_for_binding_sample.fxml"));
14 |
15 | primaryStage.setTitle("Sign In");
16 |
17 | Scene scene = new Scene(root, 200, 170);
18 | scene.getStylesheets().add(getClass()
19 | .getResource("signin.css").toExternalForm());
20 |
21 |
22 |
23 | primaryStage.setScene(scene);
24 | primaryStage.show();
25 | }
26 |
27 |
28 | public static void main(String[] args) {
29 | launch(args);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter6/src/friends/HashTableBrokenDemo.java:
--------------------------------------------------------------------------------
1 | package friends;
2 |
3 | import java.util.Hashtable;
4 |
5 | /**
6 | * Created by NewProgrammer on 3/28/15.
7 | */
8 | public class HashTableBrokenDemo {
9 | public static void main(String[] args) {
10 |
11 | ContactDetail friend1 = new ContactDetail();
12 | friend1.fullName = "Jackie Allen";
13 | friend1.email = "jallen@gmail.com";
14 | friend1.facebookID = "jallen";
15 | friend1.phone="212-545-5545";
16 |
17 | Hashtable friends = new Hashtable();
18 | friends.put("Jackie", friend1);
19 |
20 | // this is a time bomb
21 | friends.put("Art", "Art Jones, ajones@gmail.com, ajones, 212-333-2121");
22 |
23 | // Cast from Object to ContactDetail
24 | String artsPhone = ((ContactDetail) friends.get("Art")).phone;
25 |
26 | System.out.println("Art's phone number is " + artsPhone);
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter5/src/mylambdas/PetMasterLambda.java:
--------------------------------------------------------------------------------
1 | package mylambdas;
2 |
3 | import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
4 |
5 | /**
6 | * Created by NewProgrammer on 3/28/15.
7 | */
8 | public class PetMasterLambda {
9 | public static void main(String[] args) {
10 |
11 |
12 | // dogs
13 | Pet myDog = new Pet();
14 |
15 | Talkative dogTalkRules = (name) -> {
16 | return "I'm a dog. My name is " + name;
17 | };
18 |
19 | System.out.println(myDog.speakup(dogTalkRules, "Sammy"));
20 |
21 | // parrots
22 | Pet myParrot = new Pet();
23 |
24 | Talkative parrotTalkRules = (name) -> {
25 | return "I'm a parrot. Don't call me " + name;
26 | };
27 |
28 | System.out.println(myDog.speakup(parrotTalkRules, "Charlie"));
29 |
30 |
31 | System.out.println(Pet.saySomething(dogTalkRules, "Mary"));
32 |
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter4/src/GradeInterpreter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class GradeInterpreter {
5 |
6 | public static void main(String[] args){
7 |
8 | interpetGrades('B'); // prints Good Job!
9 |
10 | interpetGrades('D'); // prints Try a lot harder!
11 | }
12 |
13 | static void interpetGrades(char gradeLetter){
14 | switch (gradeLetter){
15 |
16 | case 'A':
17 | System.out.println("Excellent Job!");
18 | break;
19 | case 'B':
20 | System.out.println("Good Job!");
21 | break;
22 | case 'C':
23 | System.out.println("Try harder!");
24 | break;
25 | case 'D':
26 | System.out.println("Try a lot harder!");
27 | break;
28 | }
29 |
30 | System.out.println("Done with interpreting grade " + gradeLetter);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Chapter6/src/friends/HashTableGenericsDemo.java:
--------------------------------------------------------------------------------
1 | package friends;
2 |
3 | import java.util.Hashtable;
4 |
5 | /**
6 | * Created by NewProgrammer on 3/28/15.
7 | */
8 | public class HashTableGenericsDemo {
9 | public static void main(String[] args) {
10 |
11 | ContactDetail friend1 = new ContactDetail();
12 | friend1.fullName = "Jackie Allen";
13 | friend1.email = "jallen@gmail.com";
14 | friend1.facebookID = "jallen";
15 | friend1.phone="212-545-5545";
16 |
17 | Hashtable friends = new Hashtable<>();
18 | friends.put("Jackie", friend1);
19 |
20 | // compiler will complain about this line
21 | //friends.put("Art", "Art Jones, ajones@gmail.com, ajones, 212-333-2121");
22 |
23 | // Cast from Object to ContactDetail
24 | String jackiesPhone = friends.get("Jackie").phone;
25 |
26 | System.out.println("Jackie's phone number is " + jackiesPhone);
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter4/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 1.6
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Chapter4/src/solutions/TemperatureConverter2.java:
--------------------------------------------------------------------------------
1 | package solutions;
2 |
3 | /**
4 | * Created by yfain11 on 8/12/14.
5 | */
6 | public class TemperatureConverter2 {
7 | public static String convertTemp (float temperature, char convertTo) {
8 |
9 | String convertedTemperature;
10 |
11 | switch (convertTo){
12 | case 'F':
13 | convertedTemperature = "The temperature in Fahrenheit is " + (9*temperature/5 + 32);
14 | // break;
15 | case 'C':
16 | convertedTemperature = "The temperature in Celsius is " + (temperature - 32)*5/9;
17 | break;
18 | default:
19 | convertedTemperature = "You can enter either F or C as convertTo argument";
20 | }
21 |
22 | return convertedTemperature;
23 | }
24 |
25 | public static void main(String[] args) {
26 |
27 | System.out.println("Converting 21C to Fahrenheit. " + convertTemp(21,'F'));
28 | System.out.println("Converting 70F to Celsius. " + convertTemp(70,'C'));
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Chapter11/src/niosamples/FileCopy.java:
--------------------------------------------------------------------------------
1 | package niosamples;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 |
8 | /**
9 | * Created by NewProgrammer on 3/28/15.
10 | */
11 | public class FileCopy {
12 |
13 | public static void main(String[] args) {
14 | if (args.length != 2) {
15 | System.out.println(
16 | "Please provide source and destination file names, for example:");
17 | System.out.println("java FIleCopy abc.dat copyOfabc.dat");
18 |
19 | // Exit the program
20 | System.exit(0);
21 | }
22 |
23 | Path sourcePath = Paths.get(args[0]);
24 | Path destinationPath = Paths.get(args[1]);
25 |
26 | try {
27 | Files.copy(sourcePath, destinationPath);
28 | System.out.println("The file " + args[0] + " is copied to " + args[1]);
29 |
30 | } catch (IOException ioe) {
31 | System.out.println("Can't copy file: " + ioe.getMessage());
32 | }
33 |
34 | }
35 | }
--------------------------------------------------------------------------------
/Chapter8/src/signin/Main.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.scene.control.Button;
8 | import javafx.stage.Stage;
9 |
10 | public class Main extends Application {
11 |
12 | @Override
13 | public void start(Stage primaryStage) throws Exception{
14 | Parent root = FXMLLoader.load(getClass().getResource("signin.fxml"));
15 |
16 | // Manually setting controller
17 | //FXMLLoader loader = new FXMLLoader(getClass().getResource("signin.fxml"));
18 | //loader.setController();
19 | // Parent root = loader.load();
20 |
21 | primaryStage.setTitle("Sign In");
22 |
23 | Scene scene = new Scene(root, 200, 150);
24 | scene.getStylesheets().add(getClass()
25 | .getResource("signin.css").toExternalForm());
26 |
27 | primaryStage.setScene(scene);
28 | primaryStage.show();
29 | }
30 |
31 |
32 | public static void main(String[] args) {
33 | launch(args);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/Main.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.scene.control.Button;
8 | import javafx.stage.Stage;
9 |
10 | public class Main extends Application {
11 |
12 | @Override
13 | public void start(Stage primaryStage) throws Exception{
14 | Parent root = FXMLLoader.load(getClass().getResource("signin.fxml"));
15 |
16 | // Manually setting controller
17 | //FXMLLoader loader = new FXMLLoader(getClass().getResource("signin.fxml"));
18 | //loader.setController();
19 | // Parent root = loader.load();
20 |
21 | primaryStage.setTitle("Sign In");
22 |
23 | Scene scene = new Scene(root, 200, 150);
24 | scene.getStylesheets().add(getClass()
25 | .getResource("signin.css").toExternalForm());
26 |
27 | primaryStage.setScene(scene);
28 | primaryStage.show();
29 | }
30 |
31 |
32 | public static void main(String[] args) {
33 | launch(args);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter6/src/solutions/MyContacts.java:
--------------------------------------------------------------------------------
1 | package solutions;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * Created by NewProgrammer on 3/28/15.
7 | */
8 | public class MyContacts {
9 |
10 | public static void main(String[] args) {
11 |
12 | ArrayList friends = new ArrayList<>();
13 |
14 | ContactDetail friend1 = new ContactDetail();
15 | friend1.setFullName("Jackie Allen");
16 | friend1.setEmail("jallen@gmail.com");
17 | friend1.setFacebookID("jallen");
18 | friend1.setPhone("212-545-5545");
19 |
20 | ContactDetail friend2 = new ContactDetail();
21 | friend2.setFullName("Art Jones");
22 | friend2.setEmail("ajones@gmail.com");
23 | friend2.setFacebookID("ajones");
24 | friend2.setPhone("212-333-2121");
25 |
26 | friends.add(friend1);
27 | friends.add(friend2);
28 |
29 | friends.forEach(friend -> System.out.println(friend));
30 |
31 | /* an old way to loop through a collection
32 | for (ContactDetail friend: friends){
33 | System.out.println(friend);
34 | }*/
35 |
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Chapter11/src/niosamples/MyTextFileWriter.java:
--------------------------------------------------------------------------------
1 | package niosamples;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.nio.file.StandardOpenOption;
8 | import java.time.LocalDateTime;
9 |
10 | public class MyTextFileWriter {
11 |
12 | public static void main(String[] args){
13 |
14 | System.out.println("The current directory is "+ System.getProperty("user.dir"));
15 |
16 | String myScore = "My game score is 28000 " + LocalDateTime.now() + "\n";
17 |
18 | Path path = Paths.get("data/scores.txt");
19 |
20 | try {
21 |
22 | if ( Files.exists(path)){
23 | Files.write(path, myScore.getBytes(), StandardOpenOption.APPEND);
24 | } else {
25 | Files.write(path, myScore.getBytes(), StandardOpenOption.CREATE);
26 |
27 | }
28 |
29 | System.out.println("The game score was saved at " + path.toAbsolutePath());
30 | } catch (IOException ioe) {
31 | System.out.println("Can't write file: " + ioe.getMessage());
32 | }
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter4/src/ReportCard.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by NewProgrammer on 3/28/15.
3 | */
4 | public class ReportCard {
5 |
6 | String studentName;
7 |
8 | /**
9 | The method convertGrades has one integer argument: a test score.
10 | The method returns a letter grade, A, B, C or D, depending on the score.
11 | */
12 | public char convertGrades( int testScore){
13 |
14 | char grade;
15 |
16 | if (testScore >= 90){
17 | grade = 'A';
18 | } else if (testScore >= 80 && testScore < 90){
19 | grade = 'B';
20 | }else if (testScore >= 70 && testScore < 80){
21 | grade = 'C';
22 | }else {
23 | grade = 'D';
24 | }
25 |
26 | return grade;
27 |
28 | }
29 |
30 | public static void main(String[] args){
31 |
32 | ReportCard rc = new ReportCard();
33 |
34 | char yourGrade = rc.convertGrades(88);
35 | System.out.println("Your first grade is " +
36 | yourGrade);
37 |
38 | yourGrade = rc.convertGrades(79);
39 | System.out.println("Your second grade is " +
40 | yourGrade);
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/Chapter5/src/calc/CalculatorWithLambdas.java:
--------------------------------------------------------------------------------
1 | package calc;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class CalculatorWithLambdas {
7 |
8 | // Declaring lambda expressions
9 | static ArithmeticOperation addition = (first, second) -> {
10 | double result = first + second;
11 | System.out.println("" + first + " + " +
12 | second + " = " + result );
13 | return result;
14 | };
15 |
16 | static ArithmeticOperation subtraction = (first, second) -> {
17 | double result = first - second;
18 | System.out.println("" + first + " - " +
19 | second + " = " + result );
20 | return result;
21 | };
22 |
23 | // This method performs a given arithmetic operation on the provided numbers
24 | // The first argument can be implemented as lambda expression
25 | public static double calculate(ArithmeticOperation whatToDo, double a, double b ){
26 |
27 | return whatToDo.performOperation(a,b);
28 | }
29 |
30 | public static void main(String[] args) {
31 |
32 | calculate(addition, 3.55, 50.00);
33 | calculate(subtraction, 3.55, 50.00);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Chapter6/src/solutions/ContactDetail.java:
--------------------------------------------------------------------------------
1 | package solutions;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class ContactDetail {
7 | private String fullName;
8 | private String facebookID;
9 | private String phone;
10 | private String email;
11 |
12 | public String toString(){
13 | return "Name: " + fullName + ", Facebook ID: " + facebookID +
14 | ", phone: " + phone + ", email: " + email;
15 |
16 | };
17 |
18 | public String getFullName() {
19 | return fullName;
20 | }
21 |
22 | public void setFullName(String fullName) {
23 | this.fullName = fullName;
24 | }
25 |
26 | public String getFacebookID() {
27 | return facebookID;
28 | }
29 |
30 | public void setFacebookID(String facebookID) {
31 | this.facebookID = facebookID;
32 | }
33 |
34 | public String getPhone() {
35 | return phone;
36 | }
37 |
38 | public void setPhone(String phone) {
39 | this.phone = phone;
40 | }
41 |
42 | public String getEmail() {
43 | return email;
44 | }
45 |
46 | public void setEmail(String email) {
47 | this.email = email;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Chapter11/src/niosamples/MyTextFileReader.java:
--------------------------------------------------------------------------------
1 | package niosamples;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.nio.charset.Charset;
6 | import java.nio.charset.StandardCharsets;
7 | import java.nio.file.Files;
8 | import java.nio.file.Path;
9 | import java.nio.file.Paths;
10 |
11 | public class MyTextFileReader {
12 |
13 | public static void main(String[] args){
14 |
15 | Path path = Paths.get("abc.dat");
16 |
17 | System.out.println("The absolute path is " + path.toAbsolutePath());
18 |
19 |
20 | try {
21 |
22 |
23 | if ( Files.exists(path)){
24 | System.out.println("The file size is " + Files.size(path));
25 | }
26 |
27 |
28 | BufferedReader bufferedReader= Files.newBufferedReader(path, StandardCharsets.UTF_8);
29 |
30 | String currentLine;
31 |
32 | while ((currentLine = bufferedReader.readLine()) != null){
33 |
34 | System.out.println(currentLine);
35 |
36 | }
37 | } catch (IOException ioe) {
38 | System.out.println("Can't read file: " + ioe.getMessage());
39 | }
40 |
41 |
42 | System.out.println("Your default character encoding is " + Charset.defaultCharset());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/PingPong/src/pong/pingpong.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Chapter6/src/vehicles/Car.java:
--------------------------------------------------------------------------------
1 | package vehicles;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class Car {
7 |
8 | // This private variable is visible only inside this class
9 | private String brakesCondition;
10 |
11 | // The public method brake() calls private methods
12 | // to decide which brakes to use
13 | public void brake(int pedalPressure){
14 | boolean useRegularBrakes;
15 | useRegularBrakes=
16 | checkForAntiLockBrakes (pedalPressure);
17 |
18 | if (useRegularBrakes==true){
19 | useRegularBrakes();
20 | }else{
21 | useAntiLockBrakes();
22 | }
23 | }
24 |
25 | // This private method can be called inside
26 | // this class only
27 | private boolean checkForAntiLockBrakes(int pressure){
28 | if (pressure > 100){
29 | return true;
30 | }else {
31 | return false;
32 | }
33 | }
34 |
35 | // This private method can be called inside this
36 | // class only
37 | private void useRegularBrakes(){
38 | // code that sends a signal to regular brakes
39 | }
40 |
41 | // This private method can be called inside this
42 | // class only
43 | private void useAntiLockBrakes(){
44 | // code that sends a signal to anti-lock brakes
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Chapter11/src/niosamples/MyTextFileBufferedFileWriter.java:
--------------------------------------------------------------------------------
1 | package niosamples;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.IOException;
5 | import java.nio.charset.StandardCharsets;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.nio.file.Paths;
9 | import java.nio.file.StandardOpenOption;
10 | import java.time.LocalDateTime;
11 |
12 | public class MyTextFileBufferedFileWriter {
13 |
14 | public static void main(String[] args) {
15 |
16 | String myScore = "My game score is 28000 " + LocalDateTime.now() + "\n";
17 |
18 | Path path = Paths.get("data/scores.txt");
19 |
20 | try (BufferedWriter writer = getBufferedWriter(path)) {
21 |
22 | writer.write(myScore);
23 |
24 | System.out.println("The game score was saved at " + path.toAbsolutePath());
25 | } catch (IOException ioe) {
26 | System.out.println("Can't write file: " + ioe.getMessage());
27 | }
28 |
29 | }
30 |
31 | // The factory of BufferedWriter objects
32 | private static BufferedWriter getBufferedWriter(Path path) throws IOException{
33 |
34 | if (Files.exists(path)) {
35 | return Files.newBufferedWriter(path, StandardOpenOption.APPEND);
36 | } else {
37 | return Files.newBufferedWriter(path, StandardOpenOption.CREATE);
38 |
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Chapter5/src/calc/CalculatorWithAnonymousClasses.java:
--------------------------------------------------------------------------------
1 | package calc;
2 |
3 | /**
4 | * Created by NewProgrammer on 3/28/15.
5 | */
6 | public class CalculatorWithAnonymousClasses {
7 |
8 | static ArithmeticOperation addition = new ArithmeticOperation() {
9 | public double performOperation(double first, double second) {
10 | double result = first + second;
11 | System.out.println("" + first + " * " +
12 | second + " = " + result );
13 | return result;
14 | }
15 | };
16 |
17 | static ArithmeticOperation subtraction = new ArithmeticOperation() {
18 | public double performOperation(double first, double second) {
19 | double result = first - second;
20 | System.out.println("" + first + " - " +
21 | second + " = " + result );
22 | return result;
23 | }
24 | };
25 |
26 | // This method performs a given arithmetic operation on the provided numbers
27 | // The first argument is an object that implements ArithmeticOperation
28 | public static double calculate(ArithmeticOperation whatToDo, double a, double b ){
29 |
30 | return whatToDo.performOperation(a,b);
31 | }
32 |
33 | public static void main(String[] args) {
34 |
35 | calculate(addition, 3.55, 50.00);
36 | calculate(subtraction, 3.55, 50.00);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/BindingController.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.beans.property.SimpleStringProperty;
4 | import javafx.event.ActionEvent;
5 | import javafx.fxml.FXML;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.PasswordField;
8 | import javafx.scene.control.TextField;
9 |
10 |
11 | public class BindingController {
12 |
13 | @FXML
14 | private TextField id;
15 |
16 | @FXML
17 | private PasswordField pwd;
18 |
19 | @FXML private Label errMsg;
20 |
21 | SimpleStringProperty signinError = new SimpleStringProperty();
22 |
23 |
24 | @FXML public void initialize() {
25 | System.out.println("Controller's ready. Let's bind some components");
26 |
27 | errMsg.textProperty().bind(signinError);
28 | }
29 |
30 | public void signInClicked(ActionEvent evt){
31 |
32 | String userID = id.getText();
33 | String password = pwd.getText();
34 | if (!"Yakov".equals(userID)){
35 | id.setStyle("-fx-background-color: lightpink;");
36 | signinError.set("Wrong id:" + userID);
37 |
38 | } else{
39 | id.setStyle("-fx-background-color: white;");
40 | signinError.set("");
41 | }
42 |
43 | System.out.println("got id:" + userID + ", got password: " + password);
44 |
45 | System.out.println("Hello from signInClicked method in controller");
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/BindingController.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.beans.property.SimpleStringProperty;
4 | import javafx.event.ActionEvent;
5 | import javafx.fxml.FXML;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.PasswordField;
8 | import javafx.scene.control.TextField;
9 |
10 |
11 | public class BindingController {
12 |
13 | @FXML
14 | private TextField id;
15 |
16 | @FXML
17 | private PasswordField pwd;
18 |
19 | @FXML private Label errMsg;
20 |
21 | SimpleStringProperty signinError = new SimpleStringProperty();
22 |
23 |
24 | @FXML public void initialize() {
25 | System.out.println("Controller's ready. Let's bind some components");
26 |
27 | errMsg.textProperty().bind(signinError);
28 | }
29 |
30 | public void signInClicked(ActionEvent evt){
31 |
32 | String userID = id.getText();
33 | String password = pwd.getText();
34 | if (!"Yakov".equals(userID)){
35 | id.setStyle("-fx-background-color: lightpink;");
36 | signinError.set("Wrong id:" + userID);
37 |
38 | } else{
39 | id.setStyle("-fx-background-color: white;");
40 | signinError.set("");
41 | }
42 |
43 | System.out.println("got id:" + userID + ", got password: " + password);
44 |
45 | System.out.println("Hello from signInClicked method in controller");
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v2.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.application.Platform;
4 | import javafx.scene.input.KeyCode;
5 | import javafx.scene.input.KeyEvent;
6 |
7 | // This version of the controller adds the the code to terminate the game to PingPongController_v1
8 |
9 | public class PingPongController_v2 {
10 |
11 | public void keyReleasedHandler(KeyEvent event){
12 |
13 | KeyCode keyCode = event.getCode();
14 |
15 | switch (keyCode){
16 | case UP:
17 | process_key_Up();
18 | break;
19 | case DOWN:
20 | process_key_Down();
21 | break;
22 | case N:
23 | process_key_N();
24 | break;
25 | case Q:
26 | Platform.exit(); // Terminate the application
27 | break;
28 | case S:
29 | process_key_S();
30 | break;
31 | }
32 | }
33 |
34 |
35 | private void process_key_Up() {
36 | System.out.println("Processing the Up key");
37 | }
38 |
39 | private void process_key_Down() {
40 | System.out.println("Processing the Down key");
41 | }
42 |
43 | private void process_key_N() {
44 | System.out.println("Processing the N key");
45 | }
46 |
47 | private void process_key_S() {
48 | System.out.println("Processing the S key");
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Chapter6/src/friends/HashTableDemo.java:
--------------------------------------------------------------------------------
1 | package friends;
2 |
3 | import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
4 |
5 | import java.util.Hashtable;
6 |
7 | /**
8 | * Created by NewProgrammer on 3/28/15.
9 | */
10 | public class HashTableDemo {
11 | public static void main(String[] args) {
12 |
13 | ContactDetail friend1 = new ContactDetail();
14 | friend1.fullName = "Jackie Allen";
15 | friend1.email = "jallen@gmail.com";
16 | friend1.facebookID = "jallen";
17 | friend1.phone="212-545-5545";
18 |
19 | ContactDetail friend2 = new ContactDetail();
20 | friend2.fullName = "Art Jones";
21 | friend2.email = "ajones@gmail.com";
22 | friend2.facebookID = "ajones";
23 | friend2.phone="212-333-2121";
24 |
25 | /* ContactDetail friend3 = new ContactDetail();
26 | friend3.fullName = "Art Smith";
27 | friend3.email = "asmith@gmail.com";
28 | friend3.facebookID = "asmith";
29 | friend3.phone="518-123-4040";*/
30 |
31 |
32 | Hashtable friends = new Hashtable();
33 | friends.put("Jackie", friend1);
34 | friends.put("Art", friend2);
35 |
36 | // friends.put("Art", friend3);
37 |
38 | // Cast from Object to ContactDetail
39 | String artsPhone = ((ContactDetail) friends.get("Art")).phone;
40 |
41 | System.out.println("Art's phone number is " + artsPhone);
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Chapter12/src/WebSiteReader.java:
--------------------------------------------------------------------------------
1 | import java.io.BufferedReader;
2 | import java.io.IOException;
3 | import java.io.InputStreamReader;
4 | import java.net.MalformedURLException;
5 | import java.net.URL;
6 | import java.net.URLConnection;
7 |
8 |
9 | public class WebSiteReader {
10 | public static void main(String args[]){
11 |
12 | URL url = null;
13 | URLConnection urlConn = null;
14 |
15 | try
16 | {
17 | url = new URL("http://www.google.com" );
18 | urlConn = url.openConnection();
19 | } catch( IOException e){
20 | System.out.println("Can't connect to the provided URL:" + e.toString() );
21 | }
22 |
23 | try( InputStreamReader inStream = new InputStreamReader(
24 | urlConn.getInputStream(), "UTF8");
25 | BufferedReader buff = new BufferedReader(inStream);){
26 |
27 | String currentLine;
28 |
29 | // Read and print the code of the Google's home page
30 | while ((currentLine = buff.readLine())!= null ){
31 |
32 | System.out.println(currentLine);
33 | }
34 | } catch(MalformedURLException ex){
35 | System.out.println ("Check the spelling of the URL" + ex.getMessage());
36 | }
37 | catch(IOException ioe){
38 | System.out.println("Can't read from the Internet: "+
39 | ioe.toString());
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Chapter7/Signin/src/signin/signin.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/signin.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/signin.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Chapter12/src/FileDownload.java:
--------------------------------------------------------------------------------
1 | import java.io.FileOutputStream;
2 | import java.io.IOException;
3 | import java.io.InputStream;
4 | import java.io.OutputStream;
5 | import java.net.URL;
6 | import java.net.URLConnection;
7 | import java.nio.file.Files;
8 | import java.nio.file.Path;
9 | import java.nio.file.Paths;
10 |
11 | class FileDownload{
12 |
13 | public static void main(String args[]){
14 | if (args.length!=2){
15 | System.out.println(
16 | "Proper Usage: java FileDownload FileURL DestinationFileName");
17 | System.out.println(
18 | "For example: java FileDownload http://myflex.org/yf/nyc.jpg nyc.jpg");
19 | System.exit(-1);
20 | }
21 |
22 | URLConnection fileStream=null;
23 |
24 | try{
25 | URL remoteFile=new URL(args[0]);
26 | fileStream=remoteFile.openConnection();
27 | } catch (IOException ioe){
28 | ioe.printStackTrace();
29 | }
30 |
31 | Path path = Paths.get(args[1]);
32 |
33 | try(OutputStream fOut= Files.newOutputStream(path);
34 |
35 |
36 | InputStream in = fileStream.getInputStream();){
37 |
38 | System.out.println("Downloading from " + args[0] + ". Please wait...");
39 |
40 | // Read a remote file and save it in the local one
41 |
42 | int data;
43 | while((data=in.read())!=-1){
44 | fOut.write(data);
45 | }
46 |
47 |
48 | System.out.println("Finished downloading the file. It's located at "+path.toAbsolutePath());
49 | } catch (Exception e){
50 | e.printStackTrace();
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Chapter8/src/signin/signin_for_binding_sample.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/signin_for_binding_sample.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Chapter11/src/serialization/GameStateManager.java:
--------------------------------------------------------------------------------
1 | package serialization;
2 |
3 | import java.io.IOException;
4 | import java.io.ObjectInputStream;
5 | import java.io.ObjectOutputStream;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.nio.file.Paths;
9 | import java.nio.file.StandardOpenOption;
10 |
11 | /**
12 | * Created by NewProgrammer on 3/28/15.
13 | */
14 | public class GameStateManager {
15 |
16 | public static void main(String[] args) {
17 |
18 | // Create and populate the GameState object
19 | GameState gameState = new GameState("Mary", 45,28000,3);
20 |
21 | // The file for serialization/deserialization
22 | Path path = Paths.get("gamestate.ser");
23 |
24 | saveGameState(path, gameState);
25 | System.out.println("The GameStateObject is serialized");
26 |
27 | GameState deserializedGameState = loadGameState(path);
28 | System.out.println("Deserialized game state; " + deserializedGameState);
29 |
30 | }
31 |
32 | // Serialize the gameState into a file
33 | private static void saveGameState(Path path, GameState gameState) {
34 |
35 | try (ObjectOutputStream whereToWrite =
36 | new ObjectOutputStream(Files.newOutputStream(path, StandardOpenOption.CREATE))){
37 |
38 | whereToWrite.writeObject(gameState);
39 |
40 | } catch (IOException ioe) {
41 | System.out.println("Can't serialize file: " + ioe.getMessage());
42 | }
43 | }
44 |
45 | // Deserialize the GameState from a file
46 | private static GameState loadGameState(Path path){
47 |
48 | GameState loadedGameState = null;
49 |
50 | try (ObjectInputStream whereToReadFrom =
51 | new ObjectInputStream(Files.newInputStream(path))){
52 |
53 | loadedGameState= (GameState) whereToReadFrom.readObject();
54 |
55 | } catch (ClassNotFoundException cnfe) {
56 | System.out.println("Can't find the declaration of GameState: " + cnfe.getMessage());
57 | } catch (IOException ioe) {
58 | System.out.println("Can't deserialize file: " + ioe.getMessage());
59 | }
60 |
61 | return loadedGameState;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/Chapter11/src/solution/ScoreManager.java:
--------------------------------------------------------------------------------
1 | package solution;
2 |
3 | import serialization.GameState;
4 |
5 | import java.io.*;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.nio.file.Paths;
9 | import java.nio.file.StandardOpenOption;
10 | import java.time.LocalDateTime;
11 | import java.util.*;
12 |
13 | public class ScoreManager {
14 |
15 | public static void main(String[] args) {
16 |
17 | Path path = Paths.get("scores.ser");
18 | List scores;
19 |
20 | if (Files.exists(path)) {
21 | scores = loadScores(path);
22 |
23 | } else {
24 | scores = new ArrayList<>();
25 | }
26 |
27 | Random numberGenerator = new Random();
28 |
29 | scores.add(new Score("Mary", numberGenerator.nextInt(50000), LocalDateTime.now()));
30 |
31 | System.out.println("All scores:");
32 | scores.forEach(s -> System.out.println(s));
33 |
34 | saveScores(path, scores);
35 |
36 | System.out.println("Sorted scores (highest on top):");
37 | Comparator byScoreDescending =
38 | Collections.reverseOrder(Comparator.comparing(s -> s.score));
39 |
40 | scores.stream()
41 | .sorted(byScoreDescending)
42 | .forEach(s -> System.out.println(s));
43 | }
44 |
45 | // Serialize scores into a file
46 | private static void saveScores(Path path, List gameScores) {
47 |
48 | try (ObjectOutputStream whereToWrite = new ObjectOutputStream(
49 | Files.newOutputStream(path, StandardOpenOption.CREATE))){
50 |
51 | whereToWrite.writeObject(gameScores);
52 |
53 | } catch (IOException ioe) {
54 | System.out.println("Can't serialize scores: " + ioe.getMessage());
55 | }
56 | }
57 |
58 | // Deserialize the scores from a file
59 | private static List loadScores(Path path){
60 |
61 | List loadedScores= null;
62 |
63 | try (ObjectInputStream whereToReadFrom =
64 | new ObjectInputStream(Files.newInputStream(path))){
65 |
66 | loadedScores= (List) whereToReadFrom.readObject();
67 |
68 | } catch (ClassNotFoundException cnfe) {
69 | System.out.println("Can't find the declaration of Score: " + cnfe.getMessage());
70 | } catch (IOException ioe) {
71 | System.out.println("Can't deserialize file: " + ioe.getMessage());
72 | }
73 |
74 | return loadedScores;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v3.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.application.Platform;
4 | import javafx.beans.property.DoubleProperty;
5 | import javafx.beans.property.SimpleDoubleProperty;
6 | import javafx.fxml.FXML;
7 | import javafx.scene.input.KeyCode;
8 | import javafx.scene.input.KeyEvent;
9 | import javafx.scene.shape.Circle;
10 | import javafx.scene.shape.Rectangle;
11 |
12 |
13 | // This version of the controller adds the movement of the right paddle to PingPongController_v2
14 |
15 | public class PingPongController_v3 {
16 |
17 | final int PADDLE_MOVEMENT_INCREMENT = 6;
18 |
19 | DoubleProperty currentKidPaddleY = new SimpleDoubleProperty();
20 |
21 | double allowedPaddleTopY;
22 | double allowedPaddleBottomY;
23 |
24 | @FXML
25 | Rectangle table;
26 | @FXML Rectangle compPaddle;
27 | @FXML Rectangle kidPaddle;
28 | @FXML Circle ball;
29 |
30 | public void initialize()
31 | {
32 | currentKidPaddleY.set(kidPaddle.getLayoutY());
33 | kidPaddle.layoutYProperty().bind(currentKidPaddleY);
34 |
35 | allowedPaddleTopY = PADDLE_MOVEMENT_INCREMENT;
36 | allowedPaddleBottomY = table.getHeight() - kidPaddle.getHeight() - PADDLE_MOVEMENT_INCREMENT;
37 |
38 |
39 | }
40 | public void keyReleasedHandler(KeyEvent event){
41 |
42 | KeyCode keyCode = event.getCode();
43 |
44 | switch (keyCode){
45 | case UP:
46 | process_key_Up();
47 | break;
48 | case DOWN:
49 | process_key_Down();
50 | break;
51 | case N:
52 | process_key_N();
53 | break;
54 | case Q:
55 | Platform.exit(); // Terminate the application
56 | break;
57 | case S:
58 | process_key_S();
59 | break;
60 | }
61 | }
62 |
63 |
64 | private void process_key_Up() {
65 |
66 | if (currentKidPaddleY.get() > allowedPaddleTopY) {
67 | currentKidPaddleY.set(currentKidPaddleY.get() - PADDLE_MOVEMENT_INCREMENT);
68 | }
69 | }
70 |
71 | private void process_key_Down() {
72 |
73 | if (currentKidPaddleY.get()< allowedPaddleBottomY) {
74 | currentKidPaddleY.set(currentKidPaddleY.get() + PADDLE_MOVEMENT_INCREMENT);
75 | }
76 | }
77 |
78 | private void process_key_N() {
79 | System.out.println("Processing the N key");
80 | }
81 |
82 | private void process_key_S() {
83 | System.out.println("Processing the S key");
84 | }
85 | }
--------------------------------------------------------------------------------
/TicTacToe/src/mygame/tictactoe.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
35 |
37 |
39 |
41 |
43 |
45 |
47 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/MainPureJava.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 |
4 | import javafx.application.Application;
5 | import javafx.geometry.Insets;
6 | import javafx.geometry.Pos;
7 | import javafx.scene.Scene;
8 | import javafx.scene.control.Button;
9 | import javafx.scene.control.Label;
10 | import javafx.scene.control.PasswordField;
11 | import javafx.scene.control.TextField;
12 | import javafx.scene.layout.GridPane;
13 | import javafx.stage.Stage;
14 |
15 | public class MainPureJava extends Application {
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | final int TWO_COLUMN_SPAN = 2;
20 |
21 | Label userIdLbl = new Label("User ID:");
22 | TextField userIdTxt = new TextField();
23 | Label userPwdLbl = new Label("Password:");
24 | userPwdLbl.getStyleClass().add("bluelabel");
25 | PasswordField userPwdTxt = new PasswordField();
26 |
27 | GridPane root = new GridPane();
28 | root.setVgap(20);
29 | root.setPadding(new Insets(10));
30 | root.setAlignment(Pos.CENTER);
31 | root.setId("root");
32 |
33 | // Using static methods for setting node constraints
34 | GridPane.setConstraints(userIdLbl, 0, 0);
35 | GridPane.setConstraints(userIdTxt, 1, 0);
36 | GridPane.setConstraints(userPwdLbl, 0, 1);
37 | GridPane.setConstraints(userPwdTxt, 1, 1);
38 |
39 | root.getChildren().addAll(userIdLbl, userIdTxt, userPwdLbl, userPwdTxt);
40 |
41 |
42 | Button signInBtn = new Button ("Sign In");
43 | signInBtn.setId("submitBtn"); // used in CSS
44 |
45 | // Event handler with lambda expression
46 | signInBtn.setOnAction(evt -> {
47 |
48 | String userID = userIdTxt.getText();
49 | String password = userPwdTxt.getText();
50 | if (!"Yakov".equals(userID)){
51 | userIdTxt.setStyle("-fx-background-color: lightpink;");
52 | } else{
53 | userIdTxt.setStyle("-fx-background-color: white;");
54 | }
55 |
56 | System.out.println("Got id " + userID +
57 | " and password " + password);
58 | });
59 |
60 |
61 | signInBtn.setPrefWidth(Double.MAX_VALUE); // Allow the button to be wider
62 | // using instance method for directly adding the node
63 | root.add(signInBtn,0,2,TWO_COLUMN_SPAN,1);
64 |
65 |
66 | Scene scene = new Scene(root,250,180);
67 | scene.getStylesheets().add(getClass().getResource("signin.css").toExternalForm());
68 | primaryStage.setScene(scene);
69 | primaryStage.show();
70 |
71 |
72 |
73 | }
74 |
75 | public static void main(String[] args) {
76 | launch(args);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/MainPureJava.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 |
4 | import javafx.application.Application;
5 | import javafx.geometry.Insets;
6 | import javafx.geometry.Pos;
7 | import javafx.scene.Scene;
8 | import javafx.scene.control.Button;
9 | import javafx.scene.control.Label;
10 | import javafx.scene.control.PasswordField;
11 | import javafx.scene.control.TextField;
12 | import javafx.scene.layout.GridPane;
13 | import javafx.stage.Stage;
14 |
15 | public class MainPureJava extends Application {
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | final int TWO_COLUMN_SPAN = 2;
20 |
21 | Label userIdLbl = new Label("User ID:");
22 | TextField userIdTxt = new TextField();
23 | Label userPwdLbl = new Label("Password:");
24 | userPwdLbl.getStyleClass().add("bluelabel");
25 | PasswordField userPwdTxt = new PasswordField();
26 |
27 | GridPane root = new GridPane();
28 | root.setVgap(20);
29 | root.setPadding(new Insets(10));
30 | root.setAlignment(Pos.CENTER);
31 | root.setId("root");
32 |
33 | // Using static methods for setting node constraints
34 | GridPane.setConstraints(userIdLbl, 0, 0);
35 | GridPane.setConstraints(userIdTxt, 1, 0);
36 | GridPane.setConstraints(userPwdLbl, 0, 1);
37 | GridPane.setConstraints(userPwdTxt, 1, 1);
38 |
39 | root.getChildren().addAll(userIdLbl, userIdTxt, userPwdLbl, userPwdTxt);
40 |
41 |
42 | Button signInBtn = new Button ("Sign In");
43 | signInBtn.setId("submitBtn"); // used in CSS
44 |
45 | // Event handler with lambda expression
46 | signInBtn.setOnAction(evt -> {
47 |
48 | String userID = userIdTxt.getText();
49 | String password = userPwdTxt.getText();
50 | if (!"Yakov".equals(userID)){
51 | userIdTxt.setStyle("-fx-background-color: lightpink;");
52 | } else{
53 | userIdTxt.setStyle("-fx-background-color: white;");
54 | }
55 |
56 | System.out.println("Got id " + userID +
57 | " and password " + password);
58 | });
59 |
60 |
61 | signInBtn.setPrefWidth(Double.MAX_VALUE); // Allow the button to be wider
62 | // using instance method for directly adding the node
63 | root.add(signInBtn,0,2,TWO_COLUMN_SPAN,1);
64 |
65 |
66 | Scene scene = new Scene(root,250,180);
67 | scene.getStylesheets().add(getClass().getResource("signin.css").toExternalForm());
68 | primaryStage.setScene(scene);
69 | primaryStage.show();
70 |
71 |
72 |
73 | }
74 |
75 | public static void main(String[] args) {
76 | launch(args);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Chapter8/src/signin/ControllerLongRunningThread.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Platform;
4 | import javafx.event.ActionEvent;
5 | import javafx.fxml.FXML;
6 | import javafx.scene.control.Button;
7 | import javafx.scene.control.PasswordField;
8 | import javafx.scene.control.TextField;
9 |
10 | public class ControllerLongRunningThread {
11 |
12 | @FXML
13 | private TextField id;
14 |
15 | @FXML
16 | private PasswordField pwd;
17 |
18 | public void signInClicked(ActionEvent evt){
19 |
20 | String userID = id.getText();
21 | String password = pwd.getText();
22 |
23 | rightStartOfLongRunningProcess(userID);
24 |
25 | System.out.println("got id:" + userID + ", got password: " + password);
26 |
27 | }
28 |
29 | private void rightStartOfLongRunningProcess(String uID) {
30 |
31 | /* Emulate a login process that runs 10 sec (10000 msec)
32 | as if the login server connects to remote busy servers
33 | This method creates a worker thread, which sleeps for 10 sec
34 | and then asks Platform.runLater() to perform the GUI update logic in app thread
35 | (compare user id with Yakov)
36 | The application thread continues communicating with the GUI all the time */
37 |
38 | Runnable loginTask = () -> {
39 | try {
40 | Thread.sleep(10000); // Sleep for 10 sec in worker thread
41 |
42 | Platform.runLater(() -> { // turn the control to app thread
43 | System.out.println("sss");
44 | if (!"Yakov".equals(uID)){
45 | id.setStyle("-fx-background-color: lightpink;");
46 | } else{
47 | id.setStyle("-fx-background-color: white;");
48 | }
49 | });
50 |
51 |
52 | } catch (InterruptedException interExp) {
53 | interExp.printStackTrace();
54 | }
55 | };
56 |
57 | Thread workerThread = new Thread(loginTask);
58 | workerThread.start();
59 |
60 | }
61 |
62 | /*
63 |
64 | private void wrongStartOfLongRunningProcess(String uID) {
65 |
66 | // Emulate a login process that runs 10 sec (10000 msec)
67 | // as if the login server connects to remote busy servers
68 | // This method puts the current app thread to sleep to 10 sec
69 | // The GUI becomes frozen for 10 sec
70 |
71 | try {
72 | Thread.sleep(10000); // Sleep for 10 sec
73 | } catch (InterruptedException interExp) {
74 | interExp.printStackTrace();
75 | }
76 |
77 | if (!"Yakov".equals(uID)){
78 | id.setStyle("-fx-background-color: lightpink;");
79 | } else{
80 | id.setStyle("-fx-background-color: white;");
81 | }
82 | }
83 | */
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/Chapter8_bad/Signin/src/signin/ControllerLongRunningThread.java:
--------------------------------------------------------------------------------
1 | package signin;
2 |
3 | import javafx.application.Platform;
4 | import javafx.event.ActionEvent;
5 | import javafx.fxml.FXML;
6 | import javafx.scene.control.Button;
7 | import javafx.scene.control.PasswordField;
8 | import javafx.scene.control.TextField;
9 |
10 | public class ControllerLongRunningThread {
11 |
12 | @FXML
13 | private TextField id;
14 |
15 | @FXML
16 | private PasswordField pwd;
17 |
18 | public void signInClicked(ActionEvent evt){
19 |
20 | String userID = id.getText();
21 | String password = pwd.getText();
22 |
23 | rightStartOfLongRunningProcess(userID);
24 |
25 | System.out.println("got id:" + userID + ", got password: " + password);
26 |
27 | }
28 |
29 | private void rightStartOfLongRunningProcess(String uID) {
30 |
31 | /* Emulate a login process that runs 10 sec (10000 msec)
32 | as if the login server connects to remote busy servers
33 | This method creates a worker thread, which sleeps for 10 sec
34 | and then asks Platform.runLater() to perform the GUI update logic in app thread
35 | (compare user id with Yakov)
36 | The application thread continues communicating with the GUI all the time */
37 |
38 | Runnable loginTask = () -> {
39 | try {
40 | Thread.sleep(10000); // Sleep for 10 sec in worker thread
41 |
42 | Platform.runLater(() -> { // turn the control to app thread
43 | System.out.println("sss");
44 | if (!"Yakov".equals(uID)){
45 | id.setStyle("-fx-background-color: lightpink;");
46 | } else{
47 | id.setStyle("-fx-background-color: white;");
48 | }
49 | });
50 |
51 |
52 | } catch (InterruptedException interExp) {
53 | interExp.printStackTrace();
54 | }
55 | };
56 |
57 | Thread workerThread = new Thread(loginTask);
58 | workerThread.start();
59 |
60 | }
61 |
62 | /*
63 |
64 | private void wrongStartOfLongRunningProcess(String uID) {
65 |
66 | // Emulate a login process that runs 10 sec (10000 msec)
67 | // as if the login server connects to remote busy servers
68 | // This method puts the current app thread to sleep to 10 sec
69 | // The GUI becomes frozen for 10 sec
70 |
71 | try {
72 | Thread.sleep(10000); // Sleep for 10 sec
73 | } catch (InterruptedException interExp) {
74 | interExp.printStackTrace();
75 | }
76 |
77 | if (!"Yakov".equals(uID)){
78 | id.setStyle("-fx-background-color: lightpink;");
79 | } else{
80 | id.setStyle("-fx-background-color: white;");
81 | }
82 | }
83 | */
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v4.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.animation.KeyFrame;
4 | import javafx.animation.KeyValue;
5 | import javafx.animation.Timeline;
6 | import javafx.application.Platform;
7 | import javafx.beans.property.DoubleProperty;
8 | import javafx.beans.property.SimpleDoubleProperty;
9 | import javafx.fxml.FXML;
10 | import javafx.scene.input.KeyCode;
11 | import javafx.scene.input.KeyEvent;
12 | import javafx.scene.shape.Circle;
13 | import javafx.scene.shape.Rectangle;
14 | import javafx.util.Duration;
15 |
16 | // This version of the controller adds the method moveTheBall: the Timeline with horizontal movement to PingPongController_v3
17 |
18 | public class PingPongController_v4 {
19 |
20 | final int PADDLE_MOVEMENT_INCREMENT = 6;
21 |
22 | DoubleProperty currentKidPaddleY = new SimpleDoubleProperty();
23 |
24 |
25 | DoubleProperty ballCenterX = new SimpleDoubleProperty();
26 | DoubleProperty ballCenterY = new SimpleDoubleProperty();
27 |
28 | double allowedPaddleTopY;
29 | double allowedPaddleBottomY;
30 |
31 | Timeline timeline;
32 |
33 | @FXML
34 | Rectangle table;
35 | @FXML Rectangle compPaddle;
36 | @FXML Rectangle kidPaddle;
37 | @FXML Circle ball;
38 |
39 | public void initialize()
40 | {
41 |
42 | currentKidPaddleY.set(kidPaddle.getLayoutY());
43 | kidPaddle.layoutYProperty().bind(currentKidPaddleY);
44 |
45 | ballCenterX.set(ball.getCenterX());
46 | ballCenterY.set(ball.getCenterY());
47 |
48 | ball.centerXProperty().bind(ballCenterX);
49 | ball.centerYProperty().bind(ballCenterY);
50 |
51 |
52 | allowedPaddleTopY = PADDLE_MOVEMENT_INCREMENT;
53 | allowedPaddleBottomY = table.getHeight() - kidPaddle.getHeight() - PADDLE_MOVEMENT_INCREMENT;
54 |
55 |
56 | }
57 | public void keyReleasedHandler(KeyEvent event){
58 |
59 | KeyCode keyCode = event.getCode();
60 |
61 | switch (keyCode){
62 | case UP:
63 | process_key_Up();
64 | break;
65 | case DOWN:
66 | process_key_Down();
67 | break;
68 | case N:
69 | process_key_N();
70 | break;
71 | case Q:
72 | Platform.exit(); // Terminate the application
73 | break;
74 | case S:
75 | process_key_S();
76 | break;
77 | }
78 | }
79 |
80 |
81 | private void process_key_Up() {
82 |
83 | if (currentKidPaddleY.get() > allowedPaddleTopY) {
84 | currentKidPaddleY.set(currentKidPaddleY.get() - PADDLE_MOVEMENT_INCREMENT);
85 | }
86 | }
87 |
88 | private void process_key_Down() {
89 |
90 | if (currentKidPaddleY.get()< allowedPaddleBottomY) {
91 | currentKidPaddleY.set(currentKidPaddleY.get() + PADDLE_MOVEMENT_INCREMENT);
92 | }
93 | }
94 |
95 | private void process_key_N() {
96 | System.out.println("Processing the N key");
97 | }
98 |
99 | // This method serves the ball
100 | private void process_key_S() {
101 |
102 | ballCenterY.set(currentKidPaddleY.doubleValue() + kidPaddle.getHeight()/2);
103 | ballCenterX.set(kidPaddle.getLayoutX());
104 |
105 | moveTheBall();
106 |
107 | }
108 |
109 | private void moveTheBall(){
110 |
111 | timeline = new Timeline();
112 | timeline.setCycleCount(1);
113 |
114 | KeyValue keyValue = new KeyValue(ballCenterX, 0);
115 | KeyFrame keyFrame = new KeyFrame(new Duration(1000), keyValue);
116 | timeline.getKeyFrames().add(keyFrame);
117 |
118 | timeline.play();
119 |
120 | }
121 | }
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v5.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.animation.KeyFrame;
4 | import javafx.animation.Timeline;
5 | import javafx.application.Platform;
6 | import javafx.beans.property.DoubleProperty;
7 | import javafx.beans.property.SimpleDoubleProperty;
8 | import javafx.fxml.FXML;
9 | import javafx.scene.input.KeyCode;
10 | import javafx.scene.input.KeyEvent;
11 | import javafx.scene.shape.Circle;
12 | import javafx.scene.shape.Rectangle;
13 | import javafx.util.Duration;
14 |
15 | // This version of the controller modifies the method moveTheBall to use an event handler implemented as lambda
16 |
17 | public class PingPongController_v5 {
18 |
19 | final int PADDLE_MOVEMENT_INCREMENT = 6;
20 | final int BALL_MOVEMENT_INCREMENT = 5;
21 |
22 | DoubleProperty currentKidPaddleY = new SimpleDoubleProperty();
23 |
24 |
25 | DoubleProperty ballCenterX = new SimpleDoubleProperty();
26 | DoubleProperty ballCenterY = new SimpleDoubleProperty();
27 |
28 | double allowedPaddleTopY;
29 | double allowedPaddleBottomY;
30 |
31 | Timeline timeline;
32 |
33 | @FXML
34 | Rectangle table;
35 | @FXML Rectangle compPaddle;
36 | @FXML Rectangle kidPaddle;
37 | @FXML Circle ball;
38 |
39 | public void initialize()
40 | {
41 |
42 | currentKidPaddleY.set(kidPaddle.getLayoutY());
43 | kidPaddle.layoutYProperty().bind(currentKidPaddleY);
44 |
45 | ballCenterX.set(ball.getCenterX());
46 | ballCenterY.set(ball.getCenterY());
47 |
48 | ball.centerXProperty().bind(ballCenterX);
49 | ball.centerYProperty().bind(ballCenterY);
50 |
51 |
52 | allowedPaddleTopY = PADDLE_MOVEMENT_INCREMENT;
53 | allowedPaddleBottomY = table.getHeight() - kidPaddle.getHeight() - PADDLE_MOVEMENT_INCREMENT;
54 |
55 |
56 | }
57 | public void keyReleasedHandler(KeyEvent event){
58 |
59 | KeyCode keyCode = event.getCode();
60 |
61 | switch (keyCode){
62 | case UP:
63 | process_key_Up();
64 | break;
65 | case DOWN:
66 | process_key_Down();
67 | break;
68 | case N:
69 | process_key_N();
70 | break;
71 | case Q:
72 | Platform.exit(); // Terminate the application
73 | break;
74 | case S:
75 | process_key_S();
76 | break;
77 | }
78 | }
79 |
80 |
81 | private void process_key_Up() {
82 |
83 | if (currentKidPaddleY.get() > allowedPaddleTopY) {
84 | currentKidPaddleY.set(currentKidPaddleY.get() - PADDLE_MOVEMENT_INCREMENT);
85 | }
86 | }
87 |
88 | private void process_key_Down() {
89 |
90 | if (currentKidPaddleY.get()< allowedPaddleBottomY) {
91 | currentKidPaddleY.set(currentKidPaddleY.get() + PADDLE_MOVEMENT_INCREMENT);
92 | }
93 | }
94 |
95 | private void process_key_N() {
96 | System.out.println("Processing the N key");
97 | }
98 |
99 | // This method serves the ball
100 | private void process_key_S() {
101 |
102 | ballCenterY.set(currentKidPaddleY.doubleValue() + kidPaddle.getHeight()/2);
103 | ballCenterX.set(kidPaddle.getLayoutX());
104 |
105 | moveTheBall();
106 | }
107 |
108 | private void moveTheBall(){
109 |
110 |
111 | KeyFrame keyFrame = new KeyFrame(new Duration(10), event -> {
112 |
113 | System.out.println(ballCenterX);
114 | if (ballCenterX.get() > BALL_MOVEMENT_INCREMENT) {
115 |
116 | ballCenterX.set(ballCenterX.get() - BALL_MOVEMENT_INCREMENT);
117 |
118 | } else {
119 | timeline.stop();
120 | }
121 |
122 | });
123 |
124 | timeline = new Timeline(keyFrame);
125 | timeline.setCycleCount(Timeline.INDEFINITE);
126 |
127 | timeline.play();
128 |
129 | }
130 | }
--------------------------------------------------------------------------------
/PingPong/src/pong/PingPongController_v6.java:
--------------------------------------------------------------------------------
1 | package pong;
2 |
3 | import javafx.animation.KeyFrame;
4 | import javafx.animation.Timeline;
5 | import javafx.application.Platform;
6 | import javafx.beans.property.DoubleProperty;
7 | import javafx.beans.property.SimpleDoubleProperty;
8 | import javafx.fxml.FXML;
9 | import javafx.scene.input.KeyCode;
10 | import javafx.scene.input.KeyEvent;
11 | import javafx.scene.shape.Circle;
12 | import javafx.scene.shape.Rectangle;
13 | import javafx.util.Duration;
14 |
15 | import java.util.Random;
16 |
17 | // This version of the controller modifies the method moveTheBall to change not only the x-, but y-coordinate of the ball as well
18 |
19 | public class PingPongController_v6 {
20 |
21 | final int PADDLE_MOVEMENT_INCREMENT = 6;
22 | final int BALL_MOVEMENT_INCREMENT = 5;
23 |
24 | double centerTableY;
25 |
26 | DoubleProperty currentKidPaddleY = new SimpleDoubleProperty();
27 |
28 |
29 | DoubleProperty ballCenterX = new SimpleDoubleProperty();
30 | DoubleProperty ballCenterY = new SimpleDoubleProperty();
31 |
32 | double allowedPaddleTopY;
33 | double allowedPaddleBottomY;
34 |
35 | Timeline timeline;
36 |
37 | @FXML
38 | Rectangle table;
39 | @FXML Rectangle compPaddle;
40 | @FXML Rectangle kidPaddle;
41 | @FXML Circle ball;
42 |
43 | public void initialize()
44 | {
45 |
46 | currentKidPaddleY.set(kidPaddle.getLayoutY());
47 | kidPaddle.layoutYProperty().bind(currentKidPaddleY);
48 |
49 | ballCenterX.set(ball.getCenterX());
50 | ballCenterY.set(ball.getCenterY());
51 |
52 | ball.centerXProperty().bind(ballCenterX);
53 | ball.centerYProperty().bind(ballCenterY);
54 |
55 |
56 | allowedPaddleTopY = PADDLE_MOVEMENT_INCREMENT;
57 | allowedPaddleBottomY = table.getHeight() - kidPaddle.getHeight() - PADDLE_MOVEMENT_INCREMENT;
58 |
59 | centerTableY = table.getHeight()/2;
60 | }
61 | public void keyReleasedHandler(KeyEvent event){
62 |
63 | KeyCode keyCode = event.getCode();
64 |
65 | switch (keyCode){
66 | case UP:
67 | process_key_Up();
68 | break;
69 | case DOWN:
70 | process_key_Down();
71 | break;
72 | case N:
73 | process_key_N();
74 | break;
75 | case Q:
76 | Platform.exit(); // Terminate the application
77 | break;
78 | case S:
79 | process_key_S();
80 | break;
81 | }
82 | }
83 |
84 |
85 | private void process_key_Up() {
86 |
87 | if (currentKidPaddleY.get() > allowedPaddleTopY) {
88 | currentKidPaddleY.set(currentKidPaddleY.get() - PADDLE_MOVEMENT_INCREMENT);
89 | }
90 | }
91 |
92 | private void process_key_Down() {
93 |
94 | if (currentKidPaddleY.get()< allowedPaddleBottomY) {
95 | currentKidPaddleY.set(currentKidPaddleY.get() + PADDLE_MOVEMENT_INCREMENT);
96 | }
97 | }
98 |
99 | private void process_key_N() {
100 | System.out.println("Processing the N key");
101 | }
102 |
103 | // This method serves the ball
104 | private void process_key_S() {
105 |
106 | ballCenterY.set(currentKidPaddleY.doubleValue() + kidPaddle.getHeight()/2);
107 | ballCenterX.set(kidPaddle.getLayoutX());
108 |
109 | moveTheBall();
110 | }
111 |
112 | private void moveTheBall(){
113 |
114 | Random randomYGenerator = new Random();
115 | double randomYincrement = randomYGenerator.nextInt(BALL_MOVEMENT_INCREMENT);
116 |
117 | final boolean isServingFromTop = (ballCenterY.get() <= centerTableY)?true:false;
118 |
119 |
120 | KeyFrame keyFrame = new KeyFrame(new Duration(10), event -> {
121 |
122 | if (ballCenterX.get() >= -20) {
123 |
124 | ballCenterX.set(ballCenterX.get() - BALL_MOVEMENT_INCREMENT);
125 |
126 | if (isServingFromTop) {
127 | ballCenterY.set(ballCenterY.get() + randomYincrement);
128 |
129 | } else {
130 | ballCenterY.set(ballCenterY.get() + randomYincrement);
131 | }
132 |
133 | } else {
134 | timeline.stop();
135 |
136 | }
137 |
138 | });
139 |
140 | timeline = new Timeline(keyFrame);
141 | timeline.setCycleCount(Timeline.INDEFINITE);
142 |
143 | timeline.play();
144 |
145 | }
146 | }
--------------------------------------------------------------------------------