alright so its time for javafx challenge
so for this challenge you're going to alright so its time for javafx challenge
create simple contacts application that so for this challenge you're going to
has a single main window now the create simple contacts application that
application will allow the user to add a has a single main window now the
contact to edit contact as well as application will allow the user to add a
deleting a contact and the idea is to contact to edit contact as well as
display the contacts using the table deleting a contact and the idea is to
view control now we didn't cover table view display the contacts using the table
in the lectures but you did learn view control now we didn't cover table view
everything you need to know to use one in the lectures but you did learn
and here's what the finished application everything you need to know to use one
will look like and here's what the finished application
now they'll be a single contacts menu will look like
that contains add edit and delete items now they'll be a single contacts menu
now you want to be able to load and that contains add edit and delete items
store the contacts which isn't a now you want to be able to load and
specific javafx topic we covered in store the contacts which isn't a
this section specific javafx topic we covered in
so what I've done is provide a contact this section
data class that contains a quick and so what I've done is provide a contact
dirty way to load and store contacts data class that contains a quick and
using XML now you don't need to dirty way to load and store contacts
understand that code and also i don't using XML now you don't need to
recommend you change it it doesn't do understand that code and also i don't
any verification recommend you change it it doesn't do
so when we add and edit a contact or the any verification
values must be provided for the code to so when we add and edit a contact or the
work so if you leave the value out the code will values must be provided for the code to
throw an exception when you try to read work so if you leave the value out the code will
the values into the application and that throw an exception when you try to read
contact data classes available for the values into the application and that
downloading in the resources section of contact data classes available for
this video so the point is to not worry downloading in the resources section of
so much about the code that is dealing this video so the point is to not worry
with the xml we are focusing on javafx in so much about the code that is dealing
this particular challenge with the xml we are focusing on javafx in
when I actually have to add code to the this particular challenge
contact data class to complete the when I actually have to add code to the
challenge but what I've done is I've put contact data class to complete the
comments that indicate where your challenge but what I've done is I've put
code should go bearing in mind you don't want to comments that indicate where your
change the code that deals with the xml code should go bearing in mind you don't want to
side of things a few hints here for you change the code that deals with the xml
number one in addition to the contact side of things a few hints here for you
data class you'll need a contact class number one in addition to the contact
to store individual contacts for each data class you'll need a contact class
contact the idea is to store the first to store individual contacts for each
name the last name phone number and contact the idea is to store the first
notes and hint number two to get data name the last name phone number and
binding to work with the tableview you notes and hint number two to get data
want to store the contact information as binding to work with the tableview you
simple string property fields and third want to store the contact information as
hint the to do list application that we simple string property fields and third
worked on in an earlier lecture in this hint the to do list application that we
section covers pretty well ninety worked on in an earlier lecture in this
percent of what you'll need to complete section covers pretty well ninety
this challenge so combination of going percent of what you'll need to complete
back over that if appropriate and doing this challenge so combination of going
a bit of google researching for things back over that if appropriate and doing
like tableview and data binding a bit of google researching for things
etc specific the tableview you like tableview and data binding
should be able to get through this etc specific the tableview you
challenge so that's it that's the should be able to get through this
challenge see how you go with it pause the challenge so that's it that's the
video and when your challenge challenge see how you go with it pause the
is finished come back and we'll go through video and when your challenge
one solution and that I come up with so is finished come back and we'll go through
see you when you get back alright so one solution and that I come up with so
let's go through up one solution to see you when you get back alright so
this challenge and again i made let's go through up one solution to
this point this challenge and again i made
previously but I want to make it again this point
your code doesn't have to match the previously but I want to make it again
solution that I've come up with my ways your code doesn't have to match the
just one way of doing it if your solution that I've come up with my ways
application works using data binding and just one way of doing it if your
you've done well and completed the application works using data binding and
challenge you've done well and completed the
alright so let's start off by creating a challenge
new project so i'm gonna click on create alright so let's start off by creating a
new project and select javafx and for new project so i'm gonna click on create
this one going to call this one new project and select javafx and for
.....and finish this one going to call this one
alright so let's just expand things out .....and finish
and get started so the first thing will alright so let's just expand things out
actually do gonna change the title of the and get started so the first thing will
main window so come back here to main actually do gonna change the title of the
method it's got hello world lets main window so come back here to main
actually change that to be my contacts method it's got hello world lets
let's also change the width of the actually change that to be my contacts
window or size of the window to be 600 x let's also change the width of the
400 and if you run this now window or size of the window to be 600 x
no surprises blank window my contacts as 400 and if you run this now
the title so next let's rename the no surprises blank window my contacts as
sample . fxml file to main fxml to the title so next let's rename the
really make it clear that this is the sample . fxml file to main fxml to
fxml file for the main window i'm going really make it clear that this is the
to select the file in the project view on the fxml file for the main window i'm going
left right click select refactor then to select the file in the project view on the
name and we'll change this to main dot left right click select refactor then
Fxml and that note not only did IntelliJ name and we'll change this to main dot
change the name over here in the Fxml and that note not only did IntelliJ
project but it change it on line 13 change the name over here in the
where we reference the fxml file project but it change it on line 13
that's why refactoring is better than where we reference the fxml file
manually making the change you don't that's why refactoring is better than
have to worry about forgetting to change manually making the change you don't
in a particular area have to worry about forgetting to change
alright so continuing on next we need to in a particular area
create our data model this is where alright so continuing on next we need to
the data for the application will create our data model this is where
be stored now the data model class the data for the application will
should be the only classes that can be stored now the data model class
change the data and as I mentioned in should be the only classes that can
the challenge slides we're going to save change the data and as I mentioned in
the data to an xml file but in a real the challenge slides we're going to save
world application you might do the same or the data to an xml file but in a real
alternatively you might read it from a world application you might do the same or
database or even fetch it from the alternatively you might read it from a
internet now since only the data model database or even fetch it from the
classes can touch the data if we want to internet now since only the data model
change where the data is coming from in classes can touch the data if we want to
the future or the way we fetch the data change where the data is coming from in
and perhaps by using a different the future or the way we fetch the data
database then we should only have to and perhaps by using a different
change the data model classes we won't have to database then we should only have to
touch the rest of the application that's change the data model classes we won't have to
why keeping the data and UI separate touch the rest of the application that's
is highly recommended why keeping the data and UI separate
so let's create a new package called is highly recommended
data model i'm going to come over here so let's create a new package called
to sample right click data model i'm going to come over here
new select new package will call this to sample right click
one data model and by the way if you new select new package will call this
didn't create a new package for this one data model and by the way if you
when you wrote you're challenged code didn't create a new package for this
that's fine your code isn't real-world when you wrote you're challenged code
applications however do that's fine your code isn't real-world
have many packages and it's customary to applications however do
put the data model classes into their own have many packages and it's customary to
package I didn't do that in previous put the data model classes into their own
lectures just to keep things simple package I didn't do that in previous
alright so in this data model package lectures just to keep things simple
i'm going to create two classes contact alright so in this data model package
and contact data now the contact class i'm going to create two classes contact
will contain the information for a and contact data now the contact class
single contact and the contact data will contain the information for a
class will contain all the contacts so single contact and the contact data
this is where we'll initialize the list class will contain all the contacts so
of contacts load contacts and save this is where we'll initialize the list
contacts and if we ever want to change of contacts load contacts and save
how we load the store contacts this class contacts and if we ever want to change
the contact data class will be the only how we load the store contacts this class
class that would have to change so we'll the contact data class will be the only
start by working on the contact class class that would have to change so we'll
first let's go ahead and create that in the start by working on the contact class
data model package new Java class first let's go ahead and create that in the
contact will be the name.... data model package new Java class
...so contact will be the name....
let's start by adding fields for all the ...so
information we want for each contact so let's start by adding fields for all the
that's the first name last name cell information we want for each contact so
number as in phone number and any notes that's the first name last name cell
we want to add for that contact now will number as in phone number and any notes
store all those as strings so you might start we want to add for that contact now will
out by declaring them all as string store all those as strings so you might start
variables that wouldn't be wrong but if out by declaring them all as string
we want to take advantage of data variables that wouldn't be wrong but if
binding to update the user interface we want to take advantage of data
then we want each piece of contact data binding to update the user interface
to be a property so as I alluded to the then we want each piece of contact data
slides instead of declaring the strings to be a property so as I alluded to the
going to use the simple string properly slides instead of declaring the strings
type instead so let's go ahead and do going to use the simple string properly
those so private type instead so let's go ahead and do
so these simple string property first those so private
name set that equal to.... so these simple string property first
.... name set that equal to....
... ....
... ...
ok so next we want to do is declare a ...
constructor that accepts all these ok so next we want to do is declare a
values and then updates the properties constructor that accepts all these
now we can actually use intellijs values and then updates the properties
generate feature to do this because it will now we can actually use intellijs
create a constructors the accepts simple generate feature to do this because it will
string properly arguments we don't create a constructors the accepts simple
actually want to do that what we want to string properly arguments we don't
do is accept strings we don't want to actually want to do that what we want to
contact data class to have to know that do is accept strings we don't want to
we're storing every bit of contact contact data class to have to know that
information as a simple string property we're storing every bit of contact
so we have to write the constructor by information as a simple string property
hand I guess we could could have so we have to write the constructor by
generated it and then changed it but hand I guess we could could have
I'll just write it by hand.... generated it and then changed it but
... I'll just write it by hand....
... ...
and i'm using a set method to set the ...
value of a string property now in and i'm using a set method to set the
addition to this constructor that's over value of a string property now in
that has got the four parameters for addition to this constructor that's over
our four fields we also wanted a default that has got the four parameters for
constructor that accepts no values our four fields we also wanted a default
that's for when we're loading our saved constructor that accepts no values
contacts so let's go ahead and add that's for when we're loading our saved
that now... contacts so let's go ahead and add
... that now...
now we need setters and getters ...
for all the variables the four fields now we need setters and getters
that we defined fortunately we can use for all the variables the four fields
intellij generate feature in this that we defined fortunately we can use
case so place the cursor where we want to intellij generate feature in this
generate them as always getters and setters use case so place the cursor where we want to
all four fields and that's generate them as always getters and setters use
our setters and getters all four fields and that's
so as you scroll down here will notice that our setters and getters
intellij has actually generated two so as you scroll down here will notice that
setters one that return string and one intellij has actually generated two
that returns simple string property setters one that return string and one
that is actually fine so get first name is that returns simple string property
there but also first name property so that is actually fine so get first name is
both of those one returns a string and there but also first name property so
one returns a string property as generated both of those one returns a string and
by IntelliJ that's fine we don't need to one returns a string property as generated
worry about that but we do want to do is by IntelliJ that's fine we don't need to
override the two-string method now we worry about that but we do want to do is
may not want to use it but actually override the two-string method now we
if we ever want to print a contact we want to may not want to use it but actually
see the contact values not the object if we ever want to print a contact we want to
reference so lets add a two-string method see the contact values not the object
and just use the form fields and just use reference so lets add a two-string method
the default that actually is generated by and just use the form fields and just use
intellij which is fine and i'm going to the default that actually is generated by
leave that on the default but you may have intellij which is fine and i'm going to
not overridden that method at all or leave that on the default but you may have
you may have overridden it and return the data not overridden that method at all or
differently that's okay you may have overridden it and return the data
that isn't part of the challenge differently that's okay
solution but it's just something that I that isn't part of the challenge
would typically recommend to do solution but it's just something that I
so next we're going to work on our would typically recommend to do
contact data class which will hold all our so next we're going to work on our
contacts if you recall that i gave you contact data class which will hold all our
access to that file and mentioned in the contacts if you recall that i gave you
challenge that's available in the access to that file and mentioned in the
resources section of this video so I'm challenge that's available in the
just going to copy and paste that in now resources section of this video so I'm
but what i do first obviously is create just going to copy and paste that in now
the class so in the data model package java but what i do first obviously is create
class we're creating is contact data the class so in the data model package java
alright so we're just going to paste class we're creating is contact data
this code in alright so we're just going to paste
ok we got a set phone number and I think this code in
because i called the field phone number ok we got a set phone number and I think
in contacts so what I might do is just because i called the field phone number
quickly change that because we call it in contacts so what I might do is just
.... quickly change that because we call it
....to make sure that actually phone ....
name doesn't make sense does it ....to make sure that actually phone
so let's go back and change that just name doesn't make sense does it
undo that go back to contact lets just call this so let's go back and change that just
phone number which should be so going undo that go back to contact lets just call this
to refactor that refactor phone number which should be so going
rename will call that phone number to refactor that refactor
...and the click yes to named rename will call that phone number
them all as well and do refactor we ...and the click yes to named
should find that's all been completed them all as well and do refactor we
successfully should find that's all been completed
if we go back to contact data now it successfully
should now be happy with those changes if we go back to contact data now it
alright on full screen should now be happy with those changes
alright so this is the class and you alright on full screen
probably have a look at this if you alright so this is the class and you
attempted to challenge yourself and you probably have a look at this if you
can see that we've got various methods attempted to challenge yourself and you
here we've got this method here to load can see that we've got various methods
the contacts but again this isn't part of here we've got this method here to load
the challenge solution this XML the contacts but again this isn't part of
processing so it's not something we're the challenge solution this XML
going to discuss here but it is processing so it's not something we're
something that you would typically do going to discuss here but it is
and again note that you can change where the something that you would typically do
contacts are stored though by updating and again note that you can change where the
the contacts _file constant up contacts are stored though by updating
here on line 24 change that to the name the contacts _file constant up
of the file right now the file is going here on line 24 change that to the name
to be created in the my contacts project of the file right now the file is going
directories so you can add a path and do to be created in the my contacts project
whatever you wanted to do their so directories so you can add a path and do
looking down the list here we've got whatever you wanted to do their so
this observable list and once again looking down the list here we've got
we're doing that so that we can take this observable list and once again
advantage of data binding and the actual we're doing that so that we can take
constructor we need to create that least advantage of data binding and the actual
let's go ahead and do that so constructor we need to create that least
initializer list their was the comment view let's go ahead and do that so
we're going to change that to be initializer list their was the comment view
contacts equals FX collections dot we're going to change that to be
observable array list to initialize it as just contacts equals FX collections dot
as a reminder remember that when working observable array list to initialize it as just
with data that will display in the as a reminder remember that when working
javafx ui you I always with data that will display in the
recommend to use the javafx version of javafx ui you I always
any lists that you create we did discuss recommend to use the javafx version of
that in detail this section the reasons any lists that you create we did discuss
for that that in detail this section the reasons
in this case we're creating a list by for that
calling the observable array list method in this case we're creating a list by
from the FX collections class alright calling the observable array list method
just before we finish this video will from the FX collections class alright
need some methods for getting the just before we finish this video will
contacts adding a contact and also need some methods for getting the
deleting contact this is where we can contacts adding a contact and also
putting that code here so I'm going to leave deleting contact this is where we can
that comment out now so i'm going to putting that code here so I'm going to leave
put firstly the method to get them that comment out now so i'm going to
... put firstly the method to get them
... ...
alright so we made good progress in these ...
methods our self-explanatory they alright so we made good progress in these
should be pretty straightforward at this methods our self-explanatory they
point of the course should be pretty straightforward at this
so in addition to the code that I point of the course
provided for loading and storing the so in addition to the code that I
data from xml this is all we really need provided for loading and storing the
in the contact data class at this point data from xml this is all we really need
our data model classes are complete in the contact data class at this point
so in the next video will start work on the our data model classes are complete
user interface see you in the next video so in the next video will start work on the