Java Programming Tutorial 83 FlowLayout

Published: 24 September 2016
on channel: Grow Book
25
0

+Many more documents and lessons in http://grow-book.blogspot.com/

+Video content

what is going on everybody is bucking welcome to your 83rd drop tutorial now

we're actually going to be getting back with gooeys and learning about layouts

again after a short break learning about files and exception handling and stuff

like that so in the storm be teaching you guys about something called

flowlayout and i know we used for but this time I really want to show you guys

the details of so let's go ahead and I'm going to make a program that has some

buttons on the screen and depending on what button you click depends on what

the flowlayout it says so let's go ahead and make fruit three variables there are

going to be private so private jbutton and I just name this like a left button

and go ahead and copy that in organ name one CB in RB in this gun stand for

center button in the right button so changes to CB this can be center button

and this is going to be the right button right there

so now that we have three buns or at least three variables

what we need is a flowlayout in a container object so go ahead and make a

private low layout and you can neighbors anything you want going to my layout

because it's easy to remember and also we need a private container object and

i'm going to container just like that make sure i spelled it right and what's

good enough

so now we can go ahead and build our constructor and my classes name layout

so i'm going to name public layout for my method and this will be my

constructor so again first thing we do since we're extending jframe we can go

ahead and build our title using super Anderson name the title because I'm that

original and next when you go ahead and set our layout object that we created

right up here with flow out we'll set layout equal to Nu flow layout and this

pretty much means we want our layout to go from when we put things in there like

buns we want to be arranged from left to right kind of like Microsoft Word would

do it

so now that we made our new flowlayout and we're actually going to be changing

this depending on what button or

rest but for now that's good so now after this we need to set our container

object equal to something sort of container and set this equal to get

content pane which pretty much means get the bulk of your window and this is

pretty much just so it knows where to put stuff so now let's go ahead and set

that layout so we'll set the layout equal to layout and this pretty much

means layout equal set layout new flowlayout so I mean simple enough

now let's go ahead in we can finally do stuff with our buns

this is pretty much creating a window now let's add some stuff in it so first

thing we need is equal left button set the equal to nu J button and give it

something to put in the button and what goes in your parameters for new jbutton

is the text that's going to appear on the button so my but i have button on

screen now this is left on it so now let's go ahead and add that this screen

I just can I didn't have it oh but now i do have it on my screen says they just

added it so now we set it gave us some content and we added to our screen next

let's add some functionality to this so we do this by lb . add action and look

at that already made it for us

add actionlistener now we can either write an object in here or to make

things easier let's use an anonymous inner class and you see said method arm

well it didn't give us yet but it needs the use a new action listener and this

is the class and this is again

anonymous inner class if i change that and now if you highlight this it says it

must implement the method action listener actually performed so if you

told us to do it let's do it easily influenced

so let's just go ahead and put something like well it's better method first

before you start thinking about that public void action performed and for

parameter to action even

and events and now we can go ahead and add some functionality to this and what

we want to happen whenever we click this left button

finally after all of this adding we finally get to the meat right here the

body of our actionperformed method what we want to happen when we click the

month

well first of all we want to change that layout since we click the left button

lets go ahead and set the alignment and gun niceley shortcut right there in what

you said it too is Flo layout . left and what this is going to do is take your

entire layout for your window not just this but not just this button but the

entire layout and change everything to left alignment so by default it's going

to be in the center of the screen and when you click this is going to be on

the left

so next the only thing we need to do is put

...


On this page of the site you can watch the video online Java Programming Tutorial 83 FlowLayout with a duration of hours minute second in good quality, which was uploaded by the user Grow Book 24 September 2016, share the link with friends and acquaintances, this video has already been watched 25 times on youtube and it was liked by 0 viewers. Enjoy your viewing!