0:00:00.000,0:00:10.000
[intro music]
0:00:10.000,0:00:14.000
This presentation is delivered by the Stanford Center for Professional Development.
0:00:22.000,0:00:26.000
It's time to delve into a continuation of our last great topic. Okay?
0:00:26.000,0:00:30.000
So, it's time to continue a bit with our friend the "interactor".
0:00:30.000,0:00:34.000
And if we think about the interactor, an action listener...so last time we talked about
0:00:34.000,0:00:38.000
having buttons and buttons-generated action events. Remember that?
0:00:38.000,0:00:41.000
So we're going to do a brief review of that and push it a little bit further.
0:00:41.000,0:00:46.000
So one of things we talked about is: how in your program, say, in your init method
0:00:46.000,0:00:50.000
somewhere you might have "public void init ()"
0:00:51.000,0:00:54.000
and inside here you would set up sort of the
0:00:54.000,0:00:57.000
parts of your program that you want to actually do something, like, the various
0:00:57.000,0:01:00.000
interactors so that when someone clicks on them something happens
0:01:00.000,0:01:07.000
and then you would say, "add ActionListeners". And what this would do
0:01:07.000,0:01:10.000
is basically say,"Hey I got some buttons in my program,
0:01:10.000,0:01:14.000
I want you to be listening for buttons so when someone clicks on a button, I want you to call
0:01:14.000,0:01:17.000
a particular method for me called 'ActionPerformed'
0:01:17.000,0:01:20.000
and then based on when you call ActionPerformed, I'll figure out what button was clicked
0:01:20.000,0:01:23.000
and then actually do something." [br]Okay?
0:01:23.000,0:01:25.000
So, over here we had our friend
0:01:25.000,0:01:29.000
"public void ActionPerformed"
0:01:29.000,0:01:37.000
And "ActionPerformed" would get as its parameter something called an "ActionEvent".
0:01:37.000,0:01:41.000
And an ActionEvent (we'd just refer to it as "e"),
0:01:41.000,0:01:43.000
was basically what it would check to see
0:01:43.000,0:01:47.000
what action was actually taken or basically which button was actually clicked. Okay?
0:01:47.000,0:01:51.000
So hopefully you remember that. That's a little bit of review from last time.
0:01:51.000,0:01:53.000
Now, when we got this action event we said there are a couple things you could do with it.
0:01:54.000,0:01:58.000
Well, there is actually one main thing we talked about which you could do with it
0:01:58.000,0:02:02.000
and you could figure out which command was actually the thing that caused this action event
0:02:02.000,0:02:05.000
to be generated by saying, "Hey, you know what i want to do?"
0:02:05.000,0:02:09.000
I wanna pull out as a string (and I'll just call it 'cmd' for 'command')
0:02:09.000,0:02:12.000
the command, or, the name of the interactor
0:02:12.000,0:02:15.000
that caused this ActionPerformed method to be called." So here I would say
0:02:15.000,0:02:17.000
e dot
0:02:17.000,0:02:19.000
command equals e dot
0:02:19.000,0:02:22.000
getActionCommand
0:02:22.000,0:02:25.000
and what GetActionCommand does...it's just a method
0:02:25.000,0:02:30.000
of this ActionEvent that says,"Hey, I'll return to you the name of the interactor as a string
0:02:30.000,0:02:33.000
and buttons' names are basically just whatever displays on the button.
0:02:33.000,0:02:38.000
So then I could have some ifs in here based on this command, "if command dot equals"
0:02:38.000,0:02:40.000
and I can check for some name, then I might wanna take some action based on that button.
0:02:42.000,0:02:45.000
It turns out there something else you can ask this ActionEvent e for
0:02:45.000,0:02:47.000
other than the action command
0:02:47.000,0:02:50.000
you saw this very briefly last time in the program that we did and you're going to see it a little bit more now,
0:02:50.000,0:02:54.000
so i want to spend a little bit more time on it
0:02:54.000,0:02:56.000
which is something where you can say, "Hey e,
0:02:56.000,0:03:02.000
what i want to get from you is not the action command, I want to get the source of the action."
0:03:02.000,0:03:07.000
Now the interesting thing about what "getSource" returns to you...actually let me not put the semicolon
0:03:07.000,0:03:09.000
here right now...
0:03:09.000,0:03:12.000
is getSource actually returns to you an object.
0:03:12.000,0:03:17.000
It returns to you the object that caused this event to be generated, which means if a button was clicked
0:03:19.000,0:03:22.000
e.getActionCommand will get the name of the button
0:03:22.000,0:03:27.000
e.getSource will actually give you a reference to the button object.
0:03:27.000,0:03:31.000
So what you're getting back from this is an object. You're getting a reference to that object.
0:03:31.000,0:03:34.000
So, what does that mean for you in, sort of, your everyday life?
0:03:34.000,0:03:37.000
What that means is: over here when you want to set up your initialization
0:03:37.000,0:03:40.000
You could say, "Hey I want to create a button."
0:03:40.000,0:03:42.000
And so i'll have some button i want to create
0:03:42.000,0:03:45.000
so I'll say "new JButton"
0:03:46.000,0:03:49.000
and maybe that button, i want it to say "Hi" on it
0:03:49.000,0:03:54.000
And so one thing I can do is I could say, "hi = new JButton"and "hi"
0:03:54.000,0:03:58.000
what I'm going to do is make that an instance variable
0:03:58.000,0:04:03.000
so somewhere down here in my program where I have my ivars, my instance variables,
0:04:03.000,0:04:11.000
i would have "private JButton hi;" [br]So I just do the declaration of a variable called "Hi"
0:04:11.000,0:04:13.000
which is of type JButton and then in my initialization method
0:04:13.000,0:04:17.000
i actually create that button with the label "Hi" on it
0:04:17.000,0:04:20.000
and then i go ahead and add it somewhere to
0:04:20.000,0:04:25.000
one of the control bars in my programs. So I would say, "add 'hi' maybe to the SOUTH control bar"
0:04:25.000,0:04:27.000
because we really like adding things to the SOUTH control bar
0:04:27.000,0:04:30.000
It's just fun when buttons show up on the bottom of our screen.
0:04:30.000,0:04:33.000
So we say, "Add it there" and then wait for something to happen.
0:04:33.000,0:04:35.000
So add my action listener in case this button gets clicked.
0:04:35.000,0:04:37.000
Now when the button gets clicked over here,
0:04:37.000,0:04:40.000
what i can do
0:04:40.000,0:04:41.000
as i could actually
0:04:41.000,0:04:47.000
ask command to get its name. Right? Or I could ask the action event to get the action command name
0:04:47.000,0:04:52.000
and then i could say something like," if (cmd.equals "
0:04:52.000,0:04:56.000
and the name of the particular button that i created over there happens to be ("Hi"). If it happens to be "Hi"
0:04:57.000,0:05:02.000
then there's something i want to do, like maybe i'd want to print something on the screen or whatever the case may be.
0:05:03.000,0:05:04.000
That's one way i could write this
0:05:04.000,0:05:07.000
and this is kind of the classic way that you've seen it written before.
0:05:07.000,0:05:09.000
Okay? That's the way you saw it last time.
0:05:09.000,0:05:14.000
The other way i can write it with my friend "get source" is: rather than getting the name of the command
0:05:14.000,0:05:16.000
and checking to see if the command is equal to ("Hi")
0:05:16.000,0:05:21.000
i can actually say, "Hey, you know what? Mehran told me about this thing called e.getSource
0:05:21.000,0:05:24.000
as a matter of fact i don't even need this line for command
0:05:24.000,0:05:27.000
anymore let me just comment it out so I don't erase it, okay?
0:05:27.000,0:05:33.000
And I can say, " if (e.getSource ... this returns an object to me
0:05:33.000,0:05:38.000
i want to check to see if that object that it returns is my ("Hi") button
0:05:38.000,0:05:44.000
so here i check directly, is it equal equal to "hi" and then I do whatever I was going to do
0:05:44.000,0:05:48.000
so this has exactly the same effect as before. It's checking to see if I've gotten a button
0:05:48.000,0:05:52.000
that is the "Hi" button that was clicked. Okay?
0:05:52.000,0:05:56.000
so the difference between these two things if you kind of think about them, right?, one of them is
0:05:56.000,0:06:01.000
i'm just using the name is a string and the other ones i'm using the actual object
0:06:01.000,0:06:07.000
Now if you think about more deeply what that means if i think about the name over here, right?
0:06:07.000,0:06:12.000
If i think just in terms of the name i never need to be able to refer to the actual object
0:06:12.000,0:06:15.000
which means that if i don't need to refer to the actual object again over here
0:06:15.000,0:06:20.000
I don't necessarily need it as an instance variable. I only need it as an instance variable if I'm going to refer
0:06:20.000,0:06:24.000
to it again in someplace that's in a different method
0:06:24.000,0:06:26.000
that's some other method i may have already used it in.
0:06:26.000,0:06:31.000
So let me show you an example of what i mean by that in code to make that more concrete.
0:06:31.000,0:06:33.000
Okay, so if we come over here to code
0:06:33.000,0:06:35.000
here's essentially the code i just wrote
0:06:35.000,0:06:39.000
for basically creating a button so it's just the code i wrote on the board, right?
0:06:39.000,0:06:43.000
except I just made the font bigger. i create a button with the name "hi"
0:06:43.000,0:06:47.000
i put in the southern region. I add my action listeners to listen for that button getting clicked.
0:06:47.000,0:06:52.000
When the button gets clicked I say, "Hey. Is the thing that got clicked this button I created?"
0:06:52.000,0:06:54.000
Here i actually called it HiButton.
0:06:54.000,0:06:57.000
instead of just "hi" over there. I shortened it to "hi" so it would take up less board space.
0:06:57.000,0:07:02.000
if it's actually the source of that action is not have my high but not all
0:07:02.000,0:07:04.000
will print out below them
0:07:04.000,0:07:07.000
so i can go ahead and run this program
0:07:07.000,0:07:13.000
and if i run this program this is now i click on get the same thing i saw the four everytime i click on a get
0:07:13.000,0:07:14.000
hello there
0:07:14.000,0:07:17.000
now alternatively i could have written some slightly differently which is the
0:07:17.000,0:07:18.000
way you saw a blast time
0:07:18.000,0:07:21.000
what i can do here as i can say hey
0:07:21.000,0:07:25.000
when i'm going to do the added just go ahead and create that button and add it
0:07:25.000,0:07:29.000
all in one line because i don't need to have some variables it stores the button
0:07:29.000,0:07:35.000
because down here i'd i need to check for the source of
0:07:35.000,0:07:35.000
what that action and that was
0:07:35.000,0:07:37.000
i'm going to have a safe action event
0:07:37.000,0:07:39.000
give me your command
0:07:39.000,0:07:41.000
and the command is going to be the name of the button
0:07:41.000,0:07:45.000
so i no longer need a variable to actually store a reference to the actual
0:07:45.000,0:07:47.000
button object
0:07:47.000,0:07:51.000
because this is going to give me the name whenever i needed and so as a
0:07:51.000,0:07:53.000
result notice your i don't have an instance variable
0:07:53.000,0:07:56.000
so this is one of those things that's a trade-off it also should give you a
0:07:56.000,0:07:59.000
little bit more insight into when you have instance variables were so when you
0:07:59.000,0:08:00.000
don't have instance variables
0:08:00.000,0:08:02.000
you need to have the instance variable
0:08:02.000,0:08:08.000
in the case
0:08:08.000,0:08:11.000
where you need to have
0:08:11.000,0:08:12.000
and i want the new one
0:08:12.000,0:08:13.000
you want the instance variable in the case where
0:08:13.000,0:08:15.000
you want to be able to refer to this variable
0:08:15.000,0:08:17.000
in some method
0:08:17.000,0:08:21.000
it's different then perhaps the method which got created right so i created i
0:08:21.000,0:08:23.000
created the button over here and start somewhere
0:08:23.000,0:08:26.000
but i need to be able to refer to and some other method so it's got to be an
0:08:26.000,0:08:27.000
instance variable
0:08:27.000,0:08:34.000
if i don't need to refer to any other method which is what i saw on the second
0:08:34.000,0:08:35.000
place
0:08:35.000,0:08:36.000
i don't need to report would again here is a matter fact there's no other place
0:08:36.000,0:08:41.000
i need to refer to it after i created then i don't need distorting
0:08:41.000,0:08:52.000
and questions about her
0:08:52.000,0:08:57.000
was so that's about the neurological at the computer shouldn't try to figure out
0:08:57.000,0:08:59.000
which one could if you give it to bond with the same name
0:08:59.000,0:09:01.000
i have no idea
0:09:01.000,0:09:07.000
right and it's going to cause you problems they don't do it if you want to
0:09:07.000,0:09:08.000
see what happens go ahead and dry bread it's a bug in logic not about and what
0:09:08.000,0:09:09.000
the computers executing
0:09:09.000,0:09:19.000
any other questions are gone
0:09:19.000,0:09:21.000
up it's not going to get the actual button so
0:09:21.000,0:09:25.000
you're saying in this other case ever here
0:09:25.000,0:09:29.000
what is this thing going to return if i didn't create a variable over here
0:09:29.000,0:09:32.000
this thing starting to return some reference to your object
0:09:32.000,0:09:35.000
the only issue for you now though is you have no way of checking for equality
0:09:35.000,0:09:39.000
with some object right as you know if you don't have the same instance
0:09:39.000,0:09:42.000
variable you can check to see if that things equal the high button so if you
0:09:42.000,0:09:46.000
created high button over here just immediately added it never kept track of
0:09:46.000,0:09:46.000
it over here
0:09:46.000,0:09:48.000
this guy would return to you
0:09:48.000,9:59:59.000
a pointer too high but menu take right i got appointed a high button how do you
9:59:59.000,9:59:59.000
know it's high button
9:59:59.000,9:59:59.000
you don't because you have no way of comparing it to the actual hot button
9:59:59.000,9:59:59.000
created
9:59:59.000,9:59:59.000
and that's why we need to work
9:59:59.000,9:59:59.000
so why do i show these to differ quite of doing it the reason why i say these
9:59:59.000,9:59:59.000
two different ways of doing it is now you're actually make use of this
9:59:59.000,9:59:59.000
with respect to some other interact or is the tracks and see where we care
9:59:59.000,9:59:59.000
about doing debt source as opposed to you
9:59:59.000,9:59:59.000
the uh... action plan
9:59:59.000,9:59:59.000
so what we're gonna do next
9:59:59.000,9:59:59.000
is going to say you know allot of times and programs that you really want to
9:59:59.000,9:59:59.000
have if you want to have some way of letting the user specified
9:59:59.000,9:59:59.000
some taxed
9:59:59.000,9:59:59.000
in a program that's running interactively that's not consul right
9:59:59.000,9:59:59.000
they'd like to be able to type something and so let me just show you example of
9:59:59.000,9:59:59.000
this
9:59:59.000,9:59:59.000
dvd buchanan
9:59:59.000,9:59:59.000
so you have a program that's got what we refer to as a text feel down here
9:59:59.000,9:59:59.000
and i call that name and so if i say hey my name is maryland
9:59:59.000,9:59:59.000
it says hello maryland
9:59:59.000,9:59:59.000
and then i say are not and i was joking my name is really sally
9:59:59.000,9:59:59.000
most of you don't know this
9:59:59.000,9:59:59.000
as as a hollow sally right so it's just some way of being able to
9:59:59.000,9:59:59.000
have some taxes
9:59:59.000,9:59:59.000
field over here that the user fails and in the senate interact a right this is
9:59:59.000,9:59:59.000
just one fields dot on the console
9:59:59.000,9:59:59.000
and then do some action in the action we have to do here is to write something
9:59:59.000,9:59:59.000
the console
9:59:59.000,9:59:59.000
that makes use of the tax that the
9:59:59.000,9:59:59.000
the use your actually typed in
9:59:59.000,9:59:59.000
so how do we get something like that to work
9:59:59.000,9:59:59.000
so what we need to do is
9:59:59.000,9:59:59.000
av and interact with it's called the text field
9:59:59.000,9:59:59.000
and basically text field is
9:59:59.000,9:59:59.000
is just epping use alright it's a little place where someone can type some text
9:59:59.000,9:59:59.000
isn't interact or such as if it under control bars
9:59:59.000,9:59:59.000
and then potentially one make it enter
9:59:59.000,9:59:59.000
you get some action event that tells you unique actually or if you want you can
9:59:59.000,9:59:59.000
do something with this text
9:59:59.000,9:59:59.000
so that's the basic idea what you really get is a box and that's all you get with
9:59:59.000,9:59:59.000
it if you want to add a label to that box like the added name over here
9:59:59.000,9:59:59.000
we need to sort of specified that
9:59:59.000,9:59:59.000
and i'll show you how to do that in just a second but what you're really get at
9:59:59.000,9:59:59.000
the box in a new types in something
9:59:59.000,9:59:59.000
and then hits began turkey then potentially some of them is generated
9:59:59.000,9:59:59.000
for you
9:59:59.000,9:59:59.000
so how does that actually set up so the thing we want to create is called ej
9:59:59.000,9:59:59.000
text field ok it's just another one of these interact or just like you saw
9:59:59.000,9:59:59.000
before we had checkboxes in combo boxes and all that stuff it's just called it a
9:59:59.000,9:59:59.000
text field
9:59:59.000,9:59:59.000
off named this twenty ab
9:59:59.000,9:59:59.000
to stand for text field
9:59:59.000,9:59:59.000
and what you do when you trade and you want to be easy to use a new g tax to be
9:59:59.000,9:59:59.000
loved and what you've given as a parameter here's the funky thing
9:59:59.000,9:59:59.000
you don't give it its label
9:59:59.000,9:59:59.000
the label doesn't come with the tax till you need to create the label separately
9:59:59.000,9:59:59.000
what you give it is the size of that text feel how big it should be in terms
9:59:59.000,9:59:59.000
of the maximum number of characters that would show up in their so if we say ten
9:59:59.000,9:59:59.000
for example you're saying is i want to have some text you'll get a hold almost
9:59:59.000,9:59:59.000
ten characters and if you some font that's variable with it automatically
9:59:59.000,9:59:59.000
gives you the size of like ten ends kazan is the widest character in case
9:59:59.000,9:59:59.000
you didn't know that's just life in the city
9:59:59.000,9:59:59.000
now the funny thing about this right were let relative to add this action
9:59:59.000,9:59:59.000
performed
9:59:59.000,9:59:59.000
is one the user hits answer
9:59:59.000,9:59:59.000
if i didn't do anything else you would not actually get this call to action
9:59:59.000,9:59:59.000
performed
9:59:59.000,9:59:59.000
we'll because action performed only called for you for buttons
9:59:59.000,9:59:59.000
so what you need to do is after you actually create this text field you need
9:59:59.000,9:59:59.000
to say hey you know what
9:59:59.000,9:59:59.000
i need to let you know about this text field add something that can generate
9:59:59.000,9:59:59.000
actions and so the way you do this is a looks a little bit funky
9:59:59.000,9:59:59.000
would you tell the tax field
9:59:59.000,9:59:59.000
not and
9:59:59.000,9:59:59.000
action listeners
9:59:59.000,9:59:59.000
bits to pay
9:59:59.000,9:59:59.000
you don't need to worry about all that blood is that actually mean at a very
9:59:59.000,9:59:59.000
low level all you need to know if you're telling
9:59:59.000,9:59:59.000
this text field
9:59:59.000,9:59:59.000
hey guess what
9:59:59.000,9:59:59.000
you're going to be able to generate actions now and the thing that you're
9:59:59.000,9:59:59.000
going to let people know when you generate some actions is yourself which
9:59:59.000,9:59:59.000
is why we pass this
9:59:59.000,9:59:59.000
but anytime you create excel the youngest do this once for all text of
9:59:59.000,9:59:59.000
the via multiple text fields
9:59:59.000,9:59:59.000
you need to send this add action listener this
9:59:59.000,9:59:59.000
message
9:59:59.000,9:59:59.000
each one independently we only have one year so we only need to do it once here
9:59:59.000,9:59:59.000
but what this basically gaza says
9:59:59.000,9:59:59.000
auto text field
9:59:59.000,9:59:59.000
that you can now generate these action events as well
9:59:59.000,9:59:59.000
so after you created any sort of set up this line and you would want to add it
9:59:59.000,9:59:59.000
some more inter program write to someone your program you would probably say
9:59:59.000,9:59:59.000
bad
9:59:59.000,9:59:59.000
kidnapped and we might add ginsburg's ample in the south as we had everything
9:59:59.000,9:59:59.000
in the south
9:59:59.000,9:59:59.000
when someone takes something and it's yep and hits internet will generate some
9:59:59.000,9:59:59.000
call to action event for prefer action performed pasternak shanavas
9:59:59.000,9:59:59.000
once that gets set up
9:59:59.000,9:59:59.000
how do you actually say grout
9:59:59.000,9:59:59.000
what was the text field that generated this about right because you could have
9:59:59.000,9:59:59.000
multiple text feels that someone could have typed into it hit the enter key
9:59:59.000,9:59:59.000
what you're doing teary-eyed use your friend if you just dot me dot get sore
9:59:59.000,9:59:59.000
so inside here which are to say is
9:59:59.000,9:59:59.000
he died gets worse
9:59:59.000,9:59:59.000
is people equal to so yeah
9:59:59.000,9:59:59.000
and at this point all kinds of warning bells should go out for you and so maybe
9:59:59.000,9:59:59.000
inside here you won't be something like you want to print len
9:59:59.000,9:59:59.000
where you want to say hi and then add to it the tax that's in that text box in
9:59:59.000,9:59:59.000
the way you do that as you just say the name of whatever the text field is and
9:59:59.000,9:59:59.000
the message you sended is get taxed and what it will give you back
9:59:59.000,9:59:59.000
act is it will just returned to you this thing by it's not just returns a string
9:59:59.000,9:59:59.000
of whatever's in that box on the user enter
9:59:59.000,9:59:59.000
so that's all right out hike and then whatever text they type in just like you
9:59:59.000,9:59:59.000
saw on the program except that was writing hello
9:59:59.000,9:59:59.000
and maybe that's what we want to do
9:59:59.000,9:59:59.000
but the warning bells it should be going off now what's the problem if i've just
9:59:59.000,9:59:59.000
written the code like this
9:59:59.000,9:59:59.000
it's not an instance variable writes i have no way if this is my payment method
9:59:59.000,9:59:59.000
over here i have no way of being able to report that's me up again
9:59:59.000,9:59:59.000
out here
9:59:59.000,9:59:59.000
so i need to create the instance variable right if this is my new method
9:59:59.000,9:59:59.000
public void in eight in front of him
9:59:59.000,9:59:59.000
what i need to do is this year somewhere else in my class let's say over here
9:59:59.000,9:59:59.000
which is where i declare my art bar's right which is just lower down in the
9:59:59.000,9:59:59.000
class umar
9:59:59.000,9:59:59.000
i need to actually have prided
9:59:59.000,9:59:59.000
jamie
9:59:59.000,9:59:59.000
packs
9:59:59.000,9:59:59.000
field
9:59:59.000,9:59:59.000
grossly out and then over here rather than declaring it
9:59:59.000,9:59:59.000
i'd just create the new thier so i need to set it up with an instance variable
9:59:59.000,9:59:59.000
okay just like this on the example of the button same kind of thing that's
9:59:59.000,9:59:59.000
going on here
9:59:59.000,9:59:59.000
except the surtax feels
9:59:59.000,9:59:59.000
so let me show you an example of this code inaction
9:59:59.000,9:59:59.000
so here's a little text field example what i want to do is i'm going to create
9:59:59.000,9:59:59.000
next and the consul program some so i don't have a console
9:59:59.000,9:59:59.000
in my hand nick i'm going to have
9:59:59.000,9:59:59.000
something called name field what's name field it's just a private j text field
9:59:59.000,9:59:59.000
right it's an instance variable so i can save off name field
9:59:59.000,9:59:59.000
name field i a nationwide over here to be some new jerry text field of site and
9:59:59.000,9:59:59.000
write is exactly what i just saw over there
9:59:59.000,9:59:59.000
now when i also want to do here is the one actor funk innocent program i want
9:59:59.000,9:59:59.000
to give that box a label so before i add this box to my control bar
9:59:59.000,9:59:59.000
i'm gonna adding new jail able with jess says names all j label does it just says
9:59:59.000,9:59:59.000
hey i'm going to create something that's just this name
9:59:59.000,9:59:59.000
or just this particular these attacks attacks happens to be named and i'm
9:59:59.000,9:59:59.000
going to add
9:59:59.000,9:59:59.000
to my southern control bar
9:59:59.000,9:59:59.000
so forth it's just going to write name out there and then after i write name
9:59:59.000,9:59:59.000
i'm going to add to my name field which is going to create the box after name
9:59:59.000,9:59:59.000
and then i'm going to show you you know i'm going to do exactly what i told you
9:59:59.000,9:59:59.000
where you have to tell me name field
9:59:59.000,9:59:59.000
you're going to add action listeners of yourself
9:59:59.000,9:59:59.000
so that if you do anything
9:59:59.000,9:59:59.000
you're going to let
9:59:59.000,9:59:59.000
someone else know that you actually have done some action when the user tight
9:59:59.000,9:59:59.000
since you would please enter
9:59:59.000,9:59:59.000
that means action performed is going to get called for you because now you're
9:59:59.000,9:59:59.000
going to be able to generate events to an action listener
9:59:59.000,9:59:59.000
and inaction performed
9:59:59.000,9:59:59.000
we check you don't get source we can compare against name field 'cause we
9:59:59.000,9:59:59.000
have that saved up down here is an instance variable
9:59:59.000,9:59:59.000
and will just right out hello and then the text assisted with name field
9:59:59.000,9:59:59.000
and money
9:59:59.000,9:59:59.000
increase the tax eyes here
9:59:59.000,9:59:59.000
just so it's a little bit bigger and we can all see what's actually going on set
9:59:59.000,9:59:59.000
for one
9:59:59.000,9:59:59.000
of the wild favorite career twenty four
9:59:59.000,9:59:59.000
aquino na make a bigger
9:59:59.000,9:59:59.000
yeah the asset just in case victor
9:59:59.000,9:59:59.000
so here once again they're on
9:59:59.000,9:59:59.000
hello marilyn c and one in those it's getting a bit like it in a row right
9:59:59.000,9:59:59.000
enter entertainer entertainers that exerc entertainer
9:59:59.000,9:59:59.000
that's another one of things it's only so much fun
9:59:59.000,9:59:59.000
trying to sell these were scroll emerge from one
9:59:59.000,9:59:59.000
not a lot of time going on their why does this gap of about two minutes maybe
9:59:59.000,9:59:59.000
one
9:59:59.000,9:59:59.000
so we can do it we can go ahead and do it this way now you can get information
9:59:59.000,9:59:59.000
pentax box
9:59:59.000,9:59:59.000
any questions about text box
9:59:59.000,9:59:59.000
behind the back
9:59:59.000,9:59:59.000
yeah so basically the way layout works is every time you add things they just
9:59:59.000,9:59:59.000
get added sequentially from left to right in whichever region you're adding
9:59:59.000,9:59:59.000
them to in this case the southern region and the whole set of stuff gets honored
9:59:59.000,9:59:59.000
so if you want to space stuff out which actually need to do our ad for example
9:59:59.000,9:59:59.000
more more j labels that might have to spaces in the mental creates more space
9:59:59.000,9:59:59.000
between stuff and there's no economic are just leave it here
9:59:59.000,9:59:59.000
ikea
9:59:59.000,9:59:59.000
so here's what i think india that's kinda funky is we can actually name of
9:59:59.000,9:59:59.000
the text field
9:59:59.000,9:59:59.000
you might say but maryland this won't get source thing yeah yeah keep around
9:59:59.000,9:59:59.000
the instance there but i'm not so keen on that
9:59:59.000,9:59:59.000
what i am comwork you not is giving things name so i can just refer to them
9:59:59.000,9:59:59.000
by their name inside ok thats cool you can you can have a name
9:59:59.000,9:59:59.000
so here that exact same example just slightly differently what i want to do
9:59:59.000,9:59:59.000
is on the air
9:59:59.000,9:59:59.000
had just one more line here so this is exactly the same code i had before
9:59:59.000,9:59:59.000
except after i create the name field i say hey name field
9:59:59.000,9:59:59.000
i want to give you an action need
9:59:59.000,9:59:59.000
and that were an action command and your action command is going to be name
9:59:59.000,9:59:59.000
so whenever you generate these events yeah i can check to see if your sources
9:59:59.000,9:59:59.000
actually but the source of that event is you
9:59:59.000,9:59:59.000
or if i've given you a name
9:59:59.000,9:59:59.000
i can do the same thing i just did with buttons which is down here i can get
9:59:59.000,9:59:59.000
action command that gives me the string which is the name of the object the
9:59:59.000,9:59:59.000
created this event
9:59:59.000,9:59:59.000
and i can see if it's equal to name which is the name that i gave it
9:59:59.000,9:59:59.000
so that's just showed you a little back and forth with buttons i kinda showed
9:59:59.000,9:59:59.000
you got for it with buttons you just need them cuz you always name buttons
9:59:59.000,9:59:59.000
will check against names
9:59:59.000,9:59:59.000
but you could actually
9:59:59.000,9:59:59.000
check against the source of the button if you want to
9:59:59.000,9:59:59.000
gatech still just kinda backwards j text field you always
9:59:59.000,9:59:59.000
in some sense have the tax field that you can get with debt source but if you
9:59:59.000,9:59:59.000
want to report will by name you have to explicitly given name because name
9:59:59.000,9:59:59.000
doesn't show up as part of it right if we want the label we still need to add
9:59:59.000,9:59:59.000
the separate label name over here
9:59:59.000,9:59:59.000
this is just naming the particular events that come from that box that's
9:59:59.000,9:59:59.000
all it does
9:59:59.000,9:59:59.000
answer any questions about them
9:59:59.000,9:59:59.000
at the max max shows
9:59:59.000,9:59:59.000
oss
9:59:59.000,9:59:59.000
yen named feel the stand i've are here it's really actually no longer necessary
9:59:59.000,9:59:59.000
cuz i don't need to refer to it over here so if i wanted to make it just is
9:59:59.000,9:59:59.000
deep sting little campaigns spank sidebars thanks for playing that's real
9:59:59.000,9:59:59.000
nice of you
9:59:59.000,9:59:59.000
and everything's
9:59:59.000,9:59:59.000
although i can't
9:59:59.000,9:59:59.000
that's why i did in here cause i still need to refer to it over here to get its
9:59:59.000,9:59:59.000
what i could to be honest actually what i could do is i could just
9:59:59.000,9:59:59.000
call you get source here and get it source and get it stacks i really don't
9:59:59.000,9:59:59.000
need to
9:59:59.000,9:59:59.000
but it is better stock that makes it clear that i'm getting the texture so
9:59:59.000,9:59:59.000
there is a way around it
9:59:59.000,9:59:59.000
but the cleaner ways to actually do it this way
9:59:59.000,9:59:59.000
already
9:59:59.000,9:59:59.000
get rid of the declaration
9:59:59.000,9:59:59.000
that's like c
9:59:59.000,9:59:59.000
sang questions about that j text field
9:59:59.000,9:59:59.000
uh... yeah
9:59:59.000,9:59:59.000
on weekends
9:59:59.000,9:59:59.000
and i'll show you that no about twenty minutes
9:59:59.000,9:59:59.000
but hand free seats away so before we get there
9:59:59.000,9:59:59.000
it's not something completely different
9:59:59.000,9:59:59.000
and i think it's completely different is this a how to get to the question in the
9:59:59.000,9:59:59.000
back of the room which is
9:59:59.000,9:59:59.000
and they're on these things are all sort of showing up centered on the bottom of
9:59:59.000,9:59:59.000
the screen cut i actually have these enter actor is laid out a different way
9:59:59.000,9:59:59.000
than this way that they're getting laid out for me and in fact you can and
9:59:59.000,9:59:59.000
strangely enough the thing you used to do that is called a layout
9:59:59.000,9:59:59.000
so i'll let you know controls the layout a particular interactions now it turns
9:59:59.000,9:59:59.000
out when you use your friendly console program
9:59:59.000,9:59:59.000
or your friend of the graphics program
9:59:59.000,9:59:59.000
what you got was a layout was called the border layouts and he was a matter of
9:59:59.000,9:59:59.000
fact artists on the border layouts
9:59:59.000,9:59:59.000
you saw the boarder layout last time it looked like this
9:59:59.000,9:59:59.000
which is you had some cena region you had a north south east and west borders
9:59:59.000,9:59:59.000
which is why this thing called a border layout
9:59:59.000,9:59:59.000
and what you
9:59:59.000,9:59:59.000
what happened with that
9:59:59.000,9:59:59.000
what happened with this border layouts
9:59:59.000,9:59:59.000
powerpoint wants comply
9:59:59.000,9:59:59.000
it at the center was were all the action takes place
9:59:59.000,9:59:59.000
the console program would add a console to the sensor automatically right that
9:59:59.000,9:59:59.000
is what happens in a consul program and a graphics program would added g canvas
9:59:59.000,9:59:59.000
to the center automatically which is what you're going to draw your stuff
9:59:59.000,9:59:59.000
and the other regions are only visible if you add stuff to them so in the very
9:59:59.000,9:59:59.000
early days when you had a graphics program
9:59:59.000,9:59:59.000
that was all just graphics you would say hey mera nothing showed up at is the
9:59:59.000,9:59:59.000
self region
9:59:59.000,9:59:59.000
yeah 'cause we didn't put any interact or if they are so
9:59:59.000,9:59:59.000
these enter actor region's only show up if we actually put in a raptor on
9:59:59.000,9:59:59.000
rightly said these are referred to as control bar say saudis last time
9:59:59.000,9:59:59.000
so how do i consider different kinds of layouts so there's a couple of other
9:59:59.000,9:59:59.000
layout also think about their something called a greed layout
9:59:59.000,9:59:59.000
and and the land grant layout works is you actually creighton object called
9:59:59.000,9:59:59.000
agreed to lay out and you specify inaccurate lay out how many rows and
9:59:59.000,9:59:59.000
columns are in the great layout so
9:59:59.000,9:59:59.000
we might take you rosen three columns which means we're going to have a laying
9:59:59.000,9:59:59.000
out the look something like this is just a grade with two rooms in three columns
9:59:59.000,9:59:59.000
and i say that the code for this in just two seconds and then the nitty-gritty
9:59:59.000,9:59:59.000
details
9:59:59.000,9:59:59.000
but conceptually here's what it is
9:59:59.000,9:59:59.000
now when i had i'd ims so what i do as i say hey you know what i want to set my
9:59:59.000,9:59:59.000
layout to leave is great layout
9:59:59.000,9:59:59.000
what now happens when i had i done is is it will add items the items being the
9:59:59.000,9:59:59.000
interact urs
9:59:59.000,9:59:59.000
one-by-one starting at the top most role in the leftmost center in the last most
9:59:59.000,9:59:59.000
square
9:59:59.000,9:59:59.000
and every time i add a new element it moved over by one until i get to the end
9:59:59.000,9:59:59.000
of the row and then it automatically comes down so go sequentially across row
9:59:59.000,9:59:59.000
by roe
9:59:59.000,9:59:59.000
but allows me to contemplate things that may grade
9:59:59.000,9:59:59.000
if i want to actually be able to do things and agreed so let me show you an
9:59:59.000,9:59:59.000
example of what a grid layout might look like
9:59:59.000,9:59:59.000
world on with you lou died
9:59:59.000,9:59:59.000
so great layout
9:59:59.000,9:59:59.000
here's a simple program it has a great layout what we do is we start off
9:59:59.000,9:59:59.000
inordinate method by saying
9:59:59.000,9:59:59.000
hey you know what i want to create a layout
9:59:59.000,9:59:59.000
so i want to set the existing layout that the program is going to use to be a
9:59:59.000,9:59:59.000
new grid layout that's to come at three to rose by three columns
9:59:59.000,9:59:59.000
now one thing that's interesting about this program if you look at great layout
9:59:59.000,9:59:59.000
example
9:59:59.000,9:59:59.000
it does not extend consul program
9:59:59.000,9:59:59.000
it does not extend graphics program these are not expiry of four house and
9:59:59.000,9:59:59.000
it's beautiful life and it's beautiful children
9:59:59.000,9:59:59.000
what have i done
9:59:59.000,9:59:59.000
what i've done is set i'm just going to extend the program i don't want you to
9:59:59.000,9:59:59.000
create a console for me and i don't want you to create a g canvas for me
9:59:59.000,9:59:59.000
cuz i want to take up the whole story with my barnes baby
9:59:59.000,9:59:59.000
so that's what i'm gonna do
9:59:59.000,9:59:59.000
almanac
9:59:59.000,9:59:59.000
six new buttons and these bonds are just going to get sequentially ad in the
9:59:59.000,9:59:59.000
order you just saw and then i'm not saying a tad weiss action listeners
9:59:59.000,9:59:59.000
and i'm not going to do anything understanding or the buttons but what i
9:59:59.000,9:59:59.000
really the reason why i'm doing this
9:59:59.000,9:59:59.000
is i just want to see some big fab but
9:59:59.000,9:59:59.000
on the air like that
9:59:59.000,9:59:59.000
six buttons that take up to the whole scream
9:59:59.000,9:59:59.000
it's a good
9:59:59.000,9:59:59.000
my enter actors filled up the graded
9:59:59.000,9:59:59.000
the layout takes up as much space as possible in the screen and more
9:59:59.000,9:59:59.000
importantly each of the interac yours that i put into agreed cell takes up as
9:59:59.000,9:59:59.000
much cell as much space and the cell as possible so there's one comes along and
9:59:59.000,9:59:59.000
says
9:59:59.000,9:59:59.000
all yeah i got so much space on lay down your likely why why do you do this is
9:59:59.000,9:59:59.000
the most bring everything ever i don't hahahaha
9:59:59.000,9:59:59.000
lying
9:59:59.000,9:59:59.000
didn't have any plan that separately
9:59:59.000,9:59:59.000
driving everyone talk about a right now
9:59:59.000,9:59:59.000
maybe afterwards
9:59:59.000,9:59:59.000
such as frightening as like avnet sound effects got
9:59:59.000,9:59:59.000
check this out as i resize the window all bein small uncw big buttons
9:59:59.000,9:59:59.000
that's why we
9:59:59.000,9:59:59.000
have layout managers because the layout manager just gives conceptually says
9:59:59.000,9:59:59.000
this is how your layouts going to be
9:59:59.000,9:59:59.000
and it says i'm going to handle all the dynamics of resizing and all that stuff
9:59:59.000,9:59:59.000
for ups_ people resize the window
9:59:59.000,9:59:59.000
but i need to know how things are laid out and if you give me more space
9:59:59.000,9:59:59.000
then i need to understand the take it out
9:59:59.000,9:59:59.000
great layout not so useful page or something to seize taken if you see in
9:59:59.000,9:59:59.000
the book you know it's talking about
9:59:59.000,9:59:59.000
there's another kind of layout
9:59:59.000,9:59:59.000
which is called a table layout
9:59:59.000,9:59:59.000
so that's another kind of lay out all the flow layout when i can talk about it
9:59:59.000,9:59:59.000
all
9:59:59.000,9:59:59.000
but there's something called a table layout
9:59:59.000,9:59:59.000
any table layout is basically just like agreed layout except for the niceties so
9:59:59.000,9:59:59.000
you also give it a number of rows and columns
9:59:59.000,9:59:59.000
except where it says is rather than having each one of the interact urs fill
9:59:59.000,9:59:59.000
up itself a maximum possible size
9:59:59.000,9:59:59.000
i'm just going to give that enter actor as much space is it needs in that cell
9:59:59.000,9:59:59.000
and no more
9:59:59.000,9:59:59.000
so what does that mean
9:59:59.000,9:59:59.000
that means if i come in here rather than a grid layout i say i want to create a
9:59:59.000,9:59:59.000
new table layout
9:59:59.000,9:59:59.000
and i run this
9:59:59.000,9:59:59.000
co-ordinate add more imports
9:59:59.000,9:59:59.000
are a little guide
9:59:59.000,9:59:59.000
i mean just grab the imports from over here
9:59:59.000,9:59:59.000
me
9:59:59.000,9:59:59.000
you happy
9:59:59.000,9:59:59.000
of graphics sorry
9:59:59.000,9:59:59.000
come on table layout
9:59:59.000,9:59:59.000
though table layout
9:59:59.000,9:59:59.000
let me just show you the
9:59:59.000,9:59:59.000
nice for example it cable
9:59:59.000,9:59:59.000
didi
9:59:59.000,9:59:59.000
sometimes in life
9:59:59.000,9:59:59.000
he just got to get on with it
9:59:59.000,9:59:59.000
we got ugly with it
9:59:59.000,9:59:59.000
table layout
9:59:59.000,9:59:59.000
there's table layout
9:59:59.000,9:59:59.000
six button still
9:59:59.000,9:59:59.000
we can spell resize the window but the button there just given as much sizes
9:59:59.000,9:59:59.000
they would actually need they don't fill up the whole
9:59:59.000,9:59:59.000
region of the actually ma
9:59:59.000,9:59:59.000
table layout such something slightly more useful for us than great layout to
9:59:59.000,9:59:59.000
the question came up before which was
9:59:59.000,9:59:59.000
hey can i actually link like buttons and text fields together
9:59:59.000,9:59:59.000
to create something a little bit more funky and in fact i can do that
9:59:59.000,9:59:59.000
initially that any context outside something aloo bit more interesting
9:59:59.000,9:59:59.000
which is a program that allows for conversion in temperature so this one's
9:59:59.000,9:59:59.000
actually in the books i didn't give me the code because although
9:59:59.000,9:59:59.000
cody is actually a the coated on the books i didn't get a chance ever handout
9:59:59.000,9:59:59.000
they say it is where i got a label called degrees fahrenheit a label called
9:59:59.000,9:59:59.000
degrees celsius
9:59:59.000,9:59:59.000
and inside here we can type in some value and if we click fahrenheit to
9:59:59.000,9:59:59.000
celsius
9:59:59.000,9:59:59.000
it will automatically oil
9:59:59.000,9:59:59.000
fill in the southeast field of course one value separately to is zero celsius
9:59:59.000,9:59:59.000
the other thing that's kinda funky if i don't necessarily have to click the
9:59:59.000,9:59:59.000
button i can type in say some value and hit enter
9:59:59.000,9:59:59.000
and that's just like
9:59:59.000,9:59:59.000
clicking the button
9:59:59.000,9:59:59.000
interesting so how do i create this program well if you think about this
9:59:59.000,9:59:59.000
program first i'm going to need is these things are not supersized but they're
9:59:59.000,9:59:59.000
all laid out in a grade so i'm going to need a table layout
9:59:59.000,9:59:59.000
that has to rosen three columns
9:59:59.000,9:59:59.000
the first
9:59:59.000,9:59:59.000
element that i have here is just the label that i'm going to have a field
9:59:59.000,9:59:59.000
that the text field as a matter fact i have a specialized kind of text field
9:59:59.000,9:59:59.000
owners to specialize context field
9:59:59.000,9:59:59.000
something called the into field and a double field
9:59:59.000,9:59:59.000
they work just like text fields except you're guaranteed to get an integer
9:59:59.000,9:59:59.000
value were double value from the menu mighty but now and what happens if
9:59:59.000,9:59:59.000
someone types and and wants to come for a twitter butcher
9:59:59.000,9:59:59.000
i clicked the wrong button they want to convert age were temperature
9:59:59.000,9:59:59.000
it says an internet injuring two brings up this pop-up box and gets in their
9:59:59.000,9:59:59.000
face and say oh yeah sorry my bad
9:59:59.000,9:59:59.000
so guarantees you get a major
9:59:59.000,9:59:59.000
and then i'm going to have a button and somehow i want to link the button and
9:59:59.000,9:59:59.000
the tax bills to do the same action
9:59:59.000,9:59:59.000
so let me show you the car for that it's actually a lot shorter than it looks
9:59:59.000,9:59:59.000
like
9:59:59.000,9:59:59.000
first thing to do is a case at the layout to be a table layout notice once
9:59:59.000,9:59:59.000
again here i am extending a program 'cause i don't want to console or canvas
9:59:59.000,9:59:59.000
created for me
9:59:59.000,9:59:59.000
i want to be able to specify the whole layout
9:59:59.000,9:59:59.000
so i'm just extending a program
9:59:59.000,9:59:59.000
i say set the layout to be a table layout to come in three
9:59:59.000,9:59:59.000
and again we're going to go sequentially through all the elements of what i want
9:59:59.000,9:59:59.000
to have in the first
9:59:59.000,9:59:59.000
element
9:59:59.000,9:59:59.000
basically the first thing i want to add to my layout i don't specify intel down
9:59:59.000,9:59:59.000
here the very first thing to add to my layout is
9:59:59.000,9:59:59.000
degrees fahrenheit as a label
9:59:59.000,9:59:59.000
then i'm going to add some fahrenheit field what how did i create that
9:59:59.000,9:59:59.000
fahrenheit field actually created it up here
9:59:59.000,9:59:59.000
what i did
9:59:59.000,9:59:59.000
first was declaring it as an instance variable so fahrenheit field isn't ants
9:59:59.000,9:59:59.000
field not agape text field that you feel which is just a specialization of eighty
9:59:59.000,9:59:59.000
eight ext field
9:59:59.000,9:59:59.000
to just give you back a major other than that it works just like a text field
9:59:59.000,9:59:59.000
except drugs one show you any feel totally feel
9:59:59.000,9:59:59.000
so i created new and field i specified financial value not its initial sides
9:59:59.000,9:59:59.000
but its initial value
9:59:59.000,9:59:59.000
its initial value is thirty two
9:59:59.000,9:59:59.000
then when i say is hey fahrenheit field
9:59:59.000,9:59:59.000
i'm going to set your action command
9:59:59.000,9:59:59.000
so that when you generate actions the name associated with the actions that
9:59:59.000,9:59:59.000
you generate
9:59:59.000,9:59:59.000
is going to be af
9:59:59.000,9:59:59.000
dash greater than which we can just think of as a rogue c
9:59:59.000,9:59:59.000
that's going to be your name so i said its name and i say you're going to
9:59:59.000,9:59:59.000
generate action events
9:59:59.000,9:59:59.000
someone adn action listener g love yourself
9:59:59.000,9:59:59.000
okay just like you sabi for the text helix up now we're going with an infield
9:59:59.000,9:59:59.000
we do exactly that same thing with something called the southeast feel
9:59:59.000,9:59:59.000
tells his films also declared to be an infield
9:59:59.000,9:59:59.000
it starts off the national volume zero we set it's action command to bc goes to
9:59:59.000,9:59:59.000
ap as opposed to ap goes to see so we give it a slide a different name
9:59:59.000,9:59:59.000
and we also set yet to listen to action events
9:59:59.000,9:59:59.000
okay or did generate action events
9:59:59.000,9:59:59.000
and then we're going to lay out our great so first element of the great is
9:59:59.000,9:59:59.000
the label as we talked about before
9:59:59.000,9:59:59.000
next element of our great is our little text box that's going to actually have
9:59:59.000,9:59:59.000
the numeric value in it
9:59:59.000,9:59:59.000
and last elements of our great on the first of all of the greatest
9:59:59.000,9:59:59.000
is a button that's name is bath goes to see
9:59:59.000,9:59:59.000
and you look at this and you say hey marron if i have a button its name is
9:59:59.000,9:59:59.000
apt goes to see and i named this guy af goes to see
9:59:59.000,9:59:59.000
aren't i getting back to the previous point over here of whether that's the
9:59:59.000,9:59:59.000
logical problem where i actually have two elements that have the same name
9:59:59.000,9:59:59.000
yeah bday i have to always have the same name but i want to do exactly the same
9:59:59.000,9:59:59.000
thing in both cases so it doesn't make a difference
9:59:59.000,9:59:59.000
so what i want to do is say someone clicks the button
9:59:59.000,9:59:59.000
i'm going to do the conversion so i'm going to have some kind of those who do
9:59:59.000,9:59:59.000
the conversion
9:59:59.000,9:59:59.000
if someone type something in the text field it hits enter
9:59:59.000,9:59:59.000
i'm going to do the same thing
9:59:59.000,9:59:59.000
so this is something you see a lot of times on the web where for example if
9:59:59.000,9:59:59.000
there's a search engine you use you type in the search engine then click search
9:59:59.000,9:59:59.000
or you can just take enter how many people actually click the search button
9:59:59.000,9:59:59.000
no one how many people just and hit enter
9:59:59.000,9:59:59.000
yet isn't it nice that you can just hit enter
9:59:59.000,9:59:59.000
that's the same thing we're doing in this program which is why we went
9:59:59.000,9:59:59.000
through the extra rigmarole of setting this action command here
9:59:59.000,9:59:59.000
'cause sometimes it's just nice to hear and
9:59:59.000,9:59:59.000
and we do exactly the same thing for the grease celsius
9:59:59.000,9:59:59.000
the name that was so we add that labeled degree celsius we had the southeast
9:59:59.000,9:59:59.000
field and then we create a new button whose name is the same as the action
9:59:59.000,9:59:59.000
command for the celsius field
9:59:59.000,9:59:59.000
and then we add action listeners that sets up our entire user interface or
9:59:59.000,9:59:59.000
entire graphical user interface and a good week
9:59:59.000,9:59:59.000
and then when the user clicks on a button we say hey
9:59:59.000,9:59:59.000
let me get the action command if the action commands f goes to see which
9:59:59.000,9:59:59.000
means you are they type something in the fahrenheit field and hit enter
9:59:59.000,9:59:59.000
or they click the button
9:59:59.000,9:59:59.000
then i'll get the value in the hair fahrenheit field
9:59:59.000,9:59:59.000
because fahrenheit field integer field i just always gives me back in a major
9:59:59.000,9:59:59.000
and i do a little bit of math if you don't know the map conversion from
9:59:59.000,9:59:59.000
fahrenheit the celsius
9:59:59.000,9:59:59.000
don't worry about it this is just how you convert from fahrenheit celsius
9:59:59.000,9:59:59.000
you taking nine fifth times the fahrenheit value minus thirty two and i
9:59:59.000,9:59:59.000
give you the celtics value now you know
9:59:59.000,9:59:59.000
what i do more interestingly if i set the value in the celsius field
9:59:59.000,9:59:59.000
to be whatever value i computed
9:59:59.000,9:59:59.000
so someone just type something into the fahrenheit feel that he enter or click
9:59:59.000,9:59:59.000
the ftc_ button
9:59:59.000,9:59:59.000
but in what i do to update the screen is ice change whatever values in the
9:59:59.000,9:59:59.000
celsius field
9:59:59.000,9:59:59.000
and i destroy the receptacle of that or i should say that
9:59:59.000,9:59:59.000
compliment reciprocal the inverse the mirror image how many words can you come
9:59:59.000,9:59:59.000
up for the same thing
9:59:59.000,9:59:59.000
of that if someone does see dat
9:59:59.000,9:59:59.000
which is i get the value that's in the celsius field
9:59:59.000,9:59:59.000
i do the map it's necessary to convert herself if the fahrenheit nice at the
9:59:59.000,9:59:59.000
fair field and that's the whole program right here is my instant variables
9:59:59.000,9:59:59.000
so if i run
9:59:59.000,9:59:59.000
my little temperature program
9:59:59.000,9:59:59.000
i have my label
9:59:59.000,9:59:59.000
i have my initial value and i have my fahrenheit to celsius and if i put in
9:59:59.000,9:59:59.000
some value here like a hundred degrees fahrenheit
9:59:59.000,9:59:59.000
is thirty eight degrees celsius
9:59:59.000,9:59:59.000
and two hundred twelve degrees fahrenheit will not touch the mouse just
9:59:59.000,9:59:59.000
hit on me in turkey
9:59:59.000,9:59:59.000
uh... an er does the same thing is if i click the mouse and same thing on the
9:59:59.000,9:59:59.000
second phase zero celsius
9:59:59.000,9:59:59.000
the actor into good times and not created a whole program of the graphical
9:59:59.000,9:59:59.000
user interface and i'd like to resize and it just doesn't know a lot always
9:59:59.000,9:59:59.000
centers for me is not nice if i make it east mall
9:59:59.000,9:59:59.000
while these things don't get too small just sent a i can see the screen that's
9:59:59.000,9:59:59.000
what the state
9:59:59.000,9:59:59.000
any questions about that
9:59:59.000,9:59:59.000
how can use the mikes please
9:59:59.000,9:59:59.000
i gotta keep reminding everyone views the microphones
9:59:59.000,9:59:59.000
p
9:59:59.000,9:59:59.000
but you can look really good
9:59:59.000,9:59:59.000
uh... there are ways the with table layout you can actually get it whatever
9:59:59.000,9:59:59.000
fortuitous at hands
9:59:59.000,9:59:59.000
to actually specify different sizes for things and i just didn't do that here
9:59:59.000,9:59:59.000
it's in the book if you want to do a but we're not going to
9:59:59.000,9:59:59.000
try to push it out for in this class use it but there are ways you can
9:59:59.000,9:59:59.000
so one final thing that we want to do is you might say all this is all good well
9:59:59.000,9:59:59.000
mirror on yeah i'm not kind of fun but
9:59:59.000,9:59:59.000
really what i like to some text in some graphics together and i want to interact
9:59:59.000,9:59:59.000
recycle wanted all right
9:59:59.000,9:59:59.000
i want tax taiwan wrapped on interactive you think back to busy rethinking man
9:59:59.000,9:59:59.000
hangman you had texting had graphics
9:59:59.000,9:59:59.000
but she didn't have interacted
9:59:59.000,9:59:59.000
here you have interact there is and i show you example interact arisen tax
9:59:59.000,9:59:59.000
twenty click the button and said hi and you know
9:59:59.000,9:59:59.000
gave your name or whatever now it's time to roll the enchilada and put them all
9:59:59.000,9:59:59.000
together in our friend
9:59:59.000,9:59:59.000
text and graphics
9:59:59.000,9:59:59.000
so what text and graphics is going to do
9:59:59.000,9:59:59.000
is it basically what we want to think about is having some consul in the
9:59:59.000,9:59:59.000
program
9:59:59.000,9:59:59.000
and the graphics canvas in the program and interact or is in the program so we
9:59:59.000,9:59:59.000
can just go to town and do whatever you want to do
9:59:59.000,9:59:59.000
how do we make this happen
9:59:59.000,9:59:59.000
first thing we're going to do
9:59:59.000,9:59:59.000
you had a little bit text on the board just to get out there a little
9:59:59.000,9:59:59.000
blood circulating in your legs and i know nothing about blood clots in your
9:59:59.000,9:59:59.000
legs where you're actually traveling too long on planes and blood clot
9:59:59.000,9:59:59.000
yeah we want to talk about that
9:59:59.000,9:59:59.000
i didn't give you a small hands of a save your life beverage traveling on a
9:59:59.000,9:59:59.000
trip is longer than two hours sometime during the trip or multiple times get up
9:59:59.000,9:59:59.000
and walk around
9:59:59.000,9:59:59.000
it will save your life
9:59:59.000,9:59:59.000
but nigger ever giving a lecture for longer than two hours
9:59:59.000,9:59:59.000
get up and walk around it'll save your life to not be the blood clots but
9:59:59.000,9:59:59.000
because your students would tell you have to drive you just sitting there
9:59:59.000,9:59:59.000
going like all i know not good bread that layout were which we're not going
9:59:59.000,9:59:59.000
to get into it
9:59:59.000,9:59:59.000
but is it accidentally so text and graphics
9:59:59.000,9:59:59.000
she retains the taste great together
9:59:59.000,9:59:59.000
you can decide which ones chocolate and which ones peanut butter
9:59:59.000,9:59:59.000
lettuce text and graphics and so it's like hangman but with interactives
9:59:59.000,9:59:59.000
so what we're going to do is we're going to extend consul program
9:59:59.000,9:59:59.000
and the reason why we're going to extend the consul program he's we still need
9:59:59.000,9:59:59.000
our plan the console that's what we're going to get the text portion of doing
9:59:59.000,9:59:59.000
this interaction
9:59:59.000,9:59:59.000
it's from having the consul program
9:59:59.000,9:59:59.000
and so what we have a console program what please give this is it gives us
9:59:59.000,9:59:59.000
the borders
9:59:59.000,9:59:59.000
that we've come to know when law writing gives us the north border in the south
9:59:59.000,9:59:59.000
border and western he's and these are places where we can still play so enter
9:59:59.000,9:59:59.000
actors
9:59:59.000,9:59:59.000
the interesting thing is what's going on in the center region
9:59:59.000,9:59:59.000
and what i told you before the consul program
9:59:59.000,9:59:59.000
fills up the senate region with a place where you can put text and that's all
9:59:59.000,9:59:59.000
you can do with it
9:59:59.000,9:59:59.000
so what we're going to say it a consul program what i want to do is in the
9:59:59.000,9:59:59.000
center regent i want to give you a different layout and put stuff in that
9:59:59.000,9:59:59.000
lady out
9:59:59.000,9:59:59.000
second potentially have some text in some graphic
9:59:59.000,9:59:59.000
uh...
9:59:59.000,9:59:59.000
so what am i going to do
9:59:59.000,9:59:59.000
the first thing i want to do is i'm going to think about having some layouts
9:59:59.000,9:59:59.000
okay mine layouts going applied to this middle region
9:59:59.000,9:59:59.000
the important thing to keep in mind as the console program what used to be was
9:59:59.000,9:59:59.000
created console the filled up the entire region
9:59:59.000,9:59:59.000
now what i'm going to get is a console as my first elements
9:59:59.000,9:59:59.000
which means however i do the layout whatever i do and that lay out the very
9:59:59.000,9:59:59.000
first thing like what i have a great that has three elements to it one row
9:59:59.000,9:59:59.000
the first elements of that
9:59:59.000,9:59:59.000
will be my consul
9:59:59.000,9:59:59.000
that you don't have any control over just because of the way the consul
9:59:59.000,9:59:59.000
program works the first elements of whatever layout you used when you extend
9:59:59.000,9:59:59.000
the consul program create a layout for wall waise bhi your whatever your text
9:59:59.000,9:59:59.000
it's
9:59:59.000,9:59:59.000
now you said hey
9:59:59.000,9:59:59.000
there on your awesome tell me about graphics but if i'm doing with the
9:59:59.000,9:59:59.000
consul program how do i get graphics
9:59:59.000,9:59:59.000
we give a little trick we did in hangman which is there's this thing called the g
9:59:59.000,9:59:59.000
candidates
9:59:59.000,9:59:59.000
and what we're going to do is create agee kandicn digi cam this importantly
9:59:59.000,9:59:59.000
is actually something that we can add to a linux
9:59:59.000,9:59:59.000
so what i can do is say hey crave my consul program i'm going to create some
9:59:59.000,9:59:59.000
layout but sam i have a great that's
9:59:59.000,9:59:59.000
i'm going to create some sort of way out like maybe i have agreed me out
9:59:59.000,9:59:59.000
one comment three
9:59:59.000,9:59:59.000
which would give me dressed
9:59:59.000,9:59:59.000
i know that my first things i think up my my console what i want to do is
9:59:59.000,9:59:59.000
creepy g canvas
9:59:59.000,9:59:59.000
and ad that you can visit is my second elements
9:59:59.000,9:59:59.000
and just to be super cool to give you something that normally you'd have to
9:59:59.000,9:59:59.000
pay twelve ninety five four but i want to get at you for for
9:59:59.000,9:59:59.000
we're going to create another g hands and added over here so that she can this
9:59:59.000,9:59:59.000
bills
9:59:59.000,9:59:59.000
so what we get is consul and to different g canvases
9:59:59.000,9:59:59.000
plus we can still add interac result round or screen
9:59:59.000,9:59:59.000
at this point you should be looking at this and shock horror and delight and
9:59:59.000,9:59:59.000
going
9:59:59.000,9:59:59.000
okay marron let's all put it together and five minutes because it's just that
9:59:59.000,9:59:59.000
he
9:59:59.000,9:59:59.000
so here's how it works
9:59:59.000,9:59:59.000
text and graphics ike's ten console program
9:59:59.000,9:59:59.000
okay 'cause that's going to get my consul
9:59:59.000,9:59:59.000
in miami i say set the layout
9:59:59.000,9:59:59.000
on one new grid layout remember great layout the elements of the great layout
9:59:59.000,9:59:59.000
expand to take how much space you give them
9:59:59.000,9:59:59.000
that's what i want in this case
9:59:59.000,9:59:59.000
because what i want to say as i want to have a great i want to give the consul
9:59:59.000,9:59:59.000
one-third of the whole grade and cute and this is another third of those
9:59:59.000,9:59:59.000
grades and grown too is large as they can be
9:59:59.000,9:59:59.000
then i'm going to do is i'm going to create to canvass so i need to have some
9:59:59.000,9:59:59.000
instance variables to refer to these canvases
9:59:59.000,9:59:59.000
i am i have to canvases
9:59:59.000,9:59:59.000
which are just type is g canvas by private labels i will call them the
9:59:59.000,9:59:59.000
right canvas and the left hand yes
9:59:59.000,9:59:59.000
animals have a text field in this program just for laughs just cuz i can
9:59:59.000,9:59:59.000
and that's going to be one of my characters so i want to have interact
9:59:59.000,9:59:59.000
respect graph
9:59:59.000,9:59:59.000
what am i going to do
9:59:59.000,9:59:59.000
first thing to do it on to say that left canvas create a new canvas
9:59:59.000,9:59:59.000
that can viz
9:59:59.000,9:59:59.000
and when i do this add it's adding it to my laid out
9:59:59.000,9:59:59.000
ham adding a whole candid so what is that do it says hey told me got a great
9:59:59.000,9:59:59.000
layout here ive already filled in the first thing with the console 'cause
9:59:59.000,9:59:59.000
that's what i do on the console program
9:59:59.000,9:59:59.000
you just told me to add a canvas
9:59:59.000,9:59:59.000
element number two will be the canvas
9:59:59.000,9:59:59.000
i do the same thing again for white canvas element number three is not the
9:59:59.000,9:59:59.000
right and so i have to big canvasses on there as the second and third elements
9:59:59.000,9:59:59.000
of my grade
9:59:59.000,9:59:59.000
i got a console
9:59:59.000,9:59:59.000
grid canvas tents not going to add to interact with because it's just that
9:59:59.000,9:59:59.000
cool i'm going to create a text field which they knew gatech steel text field
9:59:59.000,9:59:59.000
i declared as a private instance variable i just showed you that
9:59:59.000,9:59:59.000
maximum size is ten
9:59:59.000,9:59:59.000
i will add a label to it and the label just going to be called some text
9:59:59.000,9:59:59.000
sold the rights some tax
9:59:59.000,9:59:59.000
in the southern region
9:59:59.000,9:59:59.000
that'll adam i text field in the southern region and that ads at this
9:59:59.000,9:59:59.000
point you should come to know involved you always gotta remember to add your
9:59:59.000,9:59:59.000
action list are very common thing that happens people create a text field and
9:59:59.000,9:59:59.000
their type in an end stuff in the program enough things happening in their
9:59:59.000,9:59:59.000
tearing their hair and they're wondering why
9:59:59.000,9:59:59.000
they just forgot to add the action list you know it learn it live it probably
9:59:59.000,9:59:59.000
it's a good time
9:59:59.000,9:59:59.000
action listener for your text field
9:59:59.000,9:59:59.000
and then i would have to buttons just for good times so i have my tech said
9:59:59.000,9:59:59.000
i'm gonna have to more buttons a button that says draw on the left
9:59:59.000,9:59:59.000
and a button that says draw on the right
9:59:59.000,9:59:59.000
so i mean show you what all these things are going to do
9:59:59.000,9:59:59.000
before i show you the rest of the program
9:59:59.000,9:59:59.000
so what i want to show you text and graphics
9:59:59.000,9:59:59.000
uh...
9:59:59.000,9:59:59.000
out my consolation
9:59:59.000,9:59:59.000
i have to you can see them but they are side by side q different canvas windows
9:59:59.000,9:59:59.000
over here here's some text i can type in high
9:59:59.000,9:59:59.000
you typed
9:59:59.000,9:59:59.000
while
9:59:59.000,9:59:59.000
that exciting
9:59:59.000,9:59:59.000
drama left in my left hand that some just run rectangles offsite i do that
9:59:59.000,9:59:59.000
just a second
9:59:59.000,9:59:59.000
draw a right
9:59:59.000,9:59:59.000
drawing in my right candidates
9:59:59.000,9:59:59.000
how did i make that happen alright on your share of the programme so i've set
9:59:59.000,9:59:59.000
everything up right console to canvases
9:59:59.000,9:59:59.000
text field and two buttons at the bottom
9:59:59.000,9:59:59.000
here is where all the actions going on when action performed is called right i
9:59:59.000,9:59:59.000
mean someone's interacting with one of the interact urs there's nothing else i
9:59:59.000,9:59:59.000
can do in the program except interact with one of the inner actors
9:59:59.000,9:59:59.000
first a check for the text field if the interaction with the text field so if
9:59:59.000,9:59:59.000
the source of the interaction with the text field i write about you typed and
9:59:59.000,9:59:59.000
the text of the text field this will go into the consul biggest anytime you do
9:59:59.000,9:59:59.000
applicable in the text always goes in the consul so it just shows up in the
9:59:59.000,9:59:59.000
consul not a whole lot exciting going on there
9:59:59.000,9:59:59.000
alternatively if the thing they did was not stipe into the text field
9:59:59.000,9:59:59.000
they clicked one of the bottoms so i say hey i'm showing i could've been there
9:59:59.000,9:59:59.000
done all with get sore throat always get action command
9:59:59.000,9:59:59.000
i'm using both just to show you that you can mix and match if you want
9:59:59.000,9:59:59.000
so i say hey what was the command get action command
9:59:59.000,9:59:59.000
if it was drawl left then what i want to do is i'm going to create a new field a
9:59:59.000,9:59:59.000
rectangle let me show you create new filled rectangle it's very simple
9:59:59.000,9:59:59.000
it just
9:59:59.000,9:59:59.000
creates a rectangle that's fifty by twenty and yes they should have been
9:59:59.000,9:59:59.000
constant i didn't make them conference i wouldn't have to scroll down and show
9:59:59.000,9:59:59.000
you the constant
9:59:59.000,9:59:59.000
i said to be filled
9:59:59.000,9:59:59.000
and i return the rectangle solid does is create a filled rectangle on say hey
9:59:59.000,9:59:59.000
your ego
9:59:59.000,9:59:59.000
and although i do is i take that filled rectangle and i added
9:59:59.000,9:59:59.000
to my left hand dates
9:59:59.000,9:59:59.000
so because that's not a graphics program i can just a tad with the rectangle one
9:59:59.000,9:59:59.000
added if i want to add the rectangle somewhere i need to specify which canvas
9:59:59.000,9:59:59.000
of my adding a few i'm adding it's the left campus icao left hand this ads
9:59:59.000,9:59:59.000
yourself this rectangle where you can add it x location twenty and at one
9:59:59.000,9:59:59.000
location left y
9:59:59.000,9:59:59.000
left wide starts out with the value ten
9:59:59.000,9:59:59.000
and every time i add something i'd space down my wife's i'm just making wide go
9:59:59.000,9:59:59.000
down to buy some spacer mt which is thirty so i was doing is trying a
9:59:59.000,9:59:59.000
rectangle and essentially moving down toward drachmir x next rectangle below
9:59:59.000,9:59:59.000
it moving down to draw the next rectangle below it
9:59:59.000,9:59:59.000
and i do exactly the same thing for the right hand side
9:59:59.000,9:59:59.000
except after a quick quick filled rectangle i have a separate whitewater
9:59:59.000,9:59:59.000
which keeps track of how low of gotten on that side in terms of the white ford
9:59:59.000,9:59:59.000
net
9:59:59.000,9:59:59.000
and i add to the right canvas
9:59:59.000,9:59:59.000
that's the only difference
9:59:59.000,9:59:59.000
so when i run this program
9:59:59.000,9:59:59.000
right some text
9:59:59.000,9:59:59.000
right again if i type and great
9:59:59.000,9:59:59.000
by typing great
9:59:59.000,9:59:59.000
and hit enter it generates the event which does the sprint lynn on the screen
9:59:59.000,9:59:59.000
right it generates this event over here this action performed
9:59:59.000,9:59:59.000
the source was text field and i write out the text on the screen
9:59:59.000,9:59:59.000
if i click on one of the buttons drama apt
9:59:59.000,9:59:59.000
draws the filled rectangle and its incremented the why on the left hand
9:59:59.000,9:59:59.000
side for next time i clicked route left
9:59:59.000,9:59:59.000
it draws at lower and lower and lower and dry right does the same thing
9:59:59.000,9:59:59.000
notice of the x location for both
9:59:59.000,9:59:59.000
this canvas and this can this when i had the rectangles are both a twenty the
9:59:59.000,9:59:59.000
reason why it shows up to a different place in the screen is because they're
9:59:59.000,9:59:59.000
two different and this is in those kind of invisible border here
9:59:59.000,9:59:59.000
so you can create cameron text
9:59:59.000,9:59:59.000
graphics and interactive altogether and just go to town any questions
9:59:59.000,9:59:59.000
all right and i will see you on wednesday