+Many more documents and lessons in http://grow-book.blogspot.com/
+Video content
what is going on guys welcome to your 85th Jeff store go and in this is where
I'm gonna be teaching you guys about something called J color chooser now
we're going to be building a program to make a box pop up and allow the user to
pick their own colors and we're going to set this color equal to variable in just
going to be doing some cool stuff of it but this is a really useful application
and we're going to be using this a lot from now on so you know it's gonna be
good
so what we're going to have pretty much on the screen as a button and when they
click the button
they're going to be able to choose your color so let's go ahead and make a
private variable referred jbutton and now just name it be four button since
i'm lazy and next we need a color variable so private color delicious name
and color color variable named color and we'll set it equal to the constant light
if i can type takes a little bit but I'll get there eventually
so now we have this color variable set to white and the last thing we need is
pretty much a panel so private jpanel and panel which is named that for
simplicity so we have three variables so let's start doing some stuff with it on
the first thing we're going to need to do is build our constructor so name a
public speech or whatever classes and doesn't take any parameters because this
constructor no parameters
now let's go ahead and add a title and move the title i cannot type today I
apologize for that although i'm not really sorry suckers and now that we
have a title
let's go ahead and make our panel so take this panel variable you just made
instead of two new jpanel and again just to take any of parameters either so now
we have a panel on the screen pretty much but we didn't add it yet but you
know we got it and next on our panel we want to set the background and this is
pretty much the background of our window our panel so next we need to set a
background color for it so set back and look at that too easy to have to type
anything
next we want to set the background color and we're just going to set it equal to
color and what this means is we're going to set the background equal to white
since our color had the value of color . white so now we pretty much got a panel
chillin on our screen so now let's go ahead and add our button to the screen
so b equals new j button doesn't take let's go ahead and for the text on our
bottomless just put choose of color because when they click the button
they're going to choose color so now we can add some functionality to do this so
be . add action listener right there and is our arguments we're just going to add
an anonymous inner class and let's go ahead and just put something like new
action i will share the way they have to do this in return new actionlistener and
again this actionlistener must implement method actionperformed and then or after
this will finally get to the good stuff so public void action performed we do
this enough hopefully action event event and now let's get to the meat of the
story of finally so whenever we click this button what we want to happen
well the first thing we want to do is we want to change that color variable but
instead of changing it to this just like a regular constant or something
we're going to let the user decide what they want to change it to so we need to
put something called J color chooser and what this allows is the user to choose
your color so just put show dialogue right there and this dialogue takes
three parameters the first parameter is the position just putting all and if you
put in all it's going to appear in the center of your screen the second
parameter is when you click this button arm a new box is going to pop up so what
do you want the title of that color chooser to be just pick your color and
last the last parameter
is the initial color that selected in you'll see it's hard to explain right
now because you can't see the box but I'm just go ahead and put color right
here so whatever the color was set as before then that's what we want to have
so let's go ahead and change that and move this over just like that and now
we're good to go but the one thing we have to watch out for is if they don't
choose a color at all
so if we give them the option she's a bunch of colors and they don't choose
anything we're going to write all right if the color that they choose is equal
to nothing and this is going to happen to be either hit X or cancel what you
want to do well we just want to take that color and set equal to whatever
color it was before or let's just go ahead and set it equal to white so if
they don't choose anything then they got
...
Auf dieser Seite können Sie das Online-Video Java Programming Tutorial 85 JColorChooser mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Grow Book 23 September 2016 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 45 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!