Java Swing GUI Basics – Java Game Dev #8


Welcome to DevFactor! the chair is a game and I think today we’re going to try to
put a little bit basically elements in so that we can have a better foundation
for testing you know what we put into the game may be doing a little bit graphic output
in the next few videos to help on in addition to the console output in you notice that in order to do this I’m and billion in class and it’s the new
classes can meet import and we talked about having came word on
the front and the back in and the reason for this is the back and
bored on John actually represent the claims data in
the front and visually represent back Tuesday to so
the back end is a like it data representation the front
end is a graphical representation in since they’re not they’re not
attached to each other if we ever wanted to like say noticed totally swap out the entire do we we
could do that without having to modify the backend code and that’s that’s a central park like
good software development it’s on called loosely coupled code and
this project kinda and here’s to a I’ll a Late Model View Controller design pattern we’re not actually gonna have
controllers but we’re gonna models for the back in and use for the front so already here you know I’m playing down to start
method and I just on meter game board object extend J frame Angie frame is a Java Swing component
forward as a generic component for building
windows so this inward object is gonna be a window and i actually
think this keyword objects gonna and a holding G panel inside it cuz we can draw on
details much easier than week and Ron G frames G
frames are used mostly for organization where’s she pills are used for content
and I think the on here from some comments and comic classes
love the key differences between J frame energy panel is yuan can have a lot of things nested in NJ
for him but you can have a lot to Jay frames
nested inside the Jeep Ram it’s like we’re gonna panels and solar
panels weekend jóvenes energy firms and I’m on the Addingham
suppress warnings to all these suppressed morning cereal
and that means document hears about serialization serialization is away basically making
it so you can output doomsday as a bit stream and then
you can import if you have a legacy load feature play its jobs on
implementation Islamabad in a lot of people like it so love a lot
of people just up to ignore it and if they want like a safety in loading just
do it yourself and there’s better ways to do you save loot for example using a sequel a database
will be so much easier to work with so if you want to look into saving games
I’d suggest looking to see lane so the jury
sir me and now has a game board object in San algeria’s for me and has the
object that represents the Bakken in has not checked it represents front
the to actually talk to each other million Eunice like when I run it I did both the concert I’ll put the
coordinates that the J racers starting at an idea little frame as likely nothing on it yet but the
frame does appear and that’s important and the frame you know it’s not showing up at the
dimensions we want to show up yet so that’s not the enemy we want our
frame to be a specific size when the user loads up that’s really important for
like an aesthetic appeal you’re gonna frame that just you have to maximize
every single time ornaments clunky so we’re gonna have to figure that out an the Java Swing EPI I’m hoping that job
FX which is very new on sexism these things to each other
swing is little bit inconsistent and how its methods work you’ll see that as a start like trying
to code this because my memory I was like oh well you know it there’s gonna
be a method to set the high and with our game board sorry are was the game were
you at the game board became in it turns out there’s a lot of methods
that involve the term size high in with that you can you can call
on these but none of them act the way you think
they were so little review the game board class right now it is a Jay from it that supercar there that’s a call to the constructor that inherits
from in store called Just Cause start method and allows us to kinda move our code out of the constructor into
other methods whose constructors are supposed to be
ten lines last that’s a job a convention saloon
keeper constructors very lean if we have to be bigger we move that
stuff out to another method helper method so here’s a game in a copy a little bit over are basic
documentation in this game is going to extend shape Surjit handle is another container
object in the Java Swing library similar to the G for him like I said
previously we usually put panels insider frames and
not the other way around panels come with this nifty little method called
Pink opponent that led a strong graphics on so we are extending our Jeep now remember to you always import and don’t
forget to leave anything out and then it’s always a good practice to
call super inside all after constructors and so at this point I’m you should think Java 2d game as a Jeep Ram I can have one or more
cheap panels inside energy panels will be what graphics card
Ron in addition to that we can J toolbars which can be used for selecting things buttons radio buttons
with also have J menu bars which are the members that appear at the
top levels every application written in Java so ray here going to be going in trying to said thing the scent is the ball first because most user interface components
in Java are by default invisible don’t ask you
why okay actually looks like I’m serving
size: sunshine is that the size and you’ll notice that this doesn’t
actually and networking because like I mentioned the jobless
will I recon people will be weird i fix that later on in the film and so
on I’m setting using the set size mattered
in his is building a new dimension so need to
mention the dimension is a X like Gordon so it’s not a and the with and represents are kinda shape over
rectangles like a boxer tango now back in nineteen board on now the
house a game pal the game board actually has two have instance that GP we call that he has a
relationship and says the composition relationship
where are game board has its own individual
copy the game we only want one one team panel throughout the entire
team because if you’re drawing on that team
panel you know this and we have another game
and we’re working with working on these all over changes previously so ill be careful that whenever we want
the game panel in the future we use the same game panel that we
created in the game board class so switching game panel to build doing so we can make
it a little bit more clear what we’re doing in this matter you know actually adding the game and into DJ from object and you know it is like
on the screen you can actually see the the amplitude by on one thing you mine under three hours
you can’t really tell if the campaign was actually inside the chief room visually in I mention earlier that job security
components are transparent by default as whiny just are so if you’re having
issues can travel seamlessly you might want to ensure that your two
components are set to visible true so said visible true another thing is lunch you set them to
visible all are the same color so another
troubleshooting step would be to on said the colors all you’re going
components two different colors is often a good practice to include a master panel which is just
such a panel to hold all your other G pills and the reason for this is because then
you don’t actually have to go modifying the G frame to modify the content became so I miss
it GE mass appeal right now but I think
I’ll actually comment that out later just for the sake
of getting you know some up on the screen by the
end of this video in if you use Eclipse ID you get this
really useful thing where you can take the object you want to act on and then
you can see all the matters that are associated
with that so I just said visible to chew and now i
think im going back and looking for more stuff in regards to sending size this object school school school
school lotsa lotsa methods lost them you never
use ever and you can I wonder why so these are
there and there’s even some like repeated methods which in 10 so the panel still isn’t showing up at
the dimensions 31 in turns out that’s cuz there’s a lot of
size methods and they all seem like they would do
very similar thing blame only a couple them actually do
exactly what we want which is to set the default size you figure to be like to set default
size that would make sense on one thing landing a job as it’s evolved over the course that
like decades so it doesn’t always follow the same
conventions on an example if this is in the color
class you have a lower case screen properties green constance rice was the
uppercase wiser Luke is green well on the developers is put in there
and then people were using its liquor another example the plane class is
mutable my would make a point questionable it’s
like left to chance X&Y in them lied be immutable means that the answers
that the public which means and not very safe years ago who’s that chick I was talking
about said in the background color you could a
black because if our J frame does not have a
backup Cory got a black our panel does we can actually see with
the panel is in the different and now that I booed up you can actually see
the panel and I mean that’s proof that our sizes aren’t working correctly yet because that’s like what
10 pixels online so it’s back to the drawing board if you get stuck on trying to figure out
Java no Java libraries on the best things to use Google around
I I didn’t really feel like you going this because I was like you know I’ve
done this so many times for I gotta figure down so yet just be careful with the the swing libraries and zooming ahead I figured out the issue
and I’m actually removing the the size we are using I’m switching a method is set preferred
size and all the methods involve size set preferred size will give you the
windows starting X which is the with and why which is the
high it takes dimension like was the other
swing size related methods I think when I ended up fine you know is
if you do like set size it actually just alex hasn’t that
doesn’t do anything but then you can maybe call like get
size will return as you can see here actually came out as
a 800×600 panel which is a pretty good starting size his
table came but at the same time the backgrounds leading Ron Parker I think that has to do with
the default layout manager which is flow layout for the JPM but the J frame is actually differently managers
borderline now so I’m gonna I’m gonna kill off the master
town right now we’re gonna see what that does there’s
also pack method that have added to the end build doing in the pack messages is hey compact
everything so that it looks nice so don’t leave any
extra white space and you lose their there we go we got
our our panel up and running with a black background fitting exactly
800×600 which is what we wanted and so we’re pretty much in a prime place to start building actually drawing
graphics on the screen and the graphics that represent the position the J research object so it’s is kinda exciting P closed
actually drawing on the screen your IQ test here like few we finally got it in for
servers I’m thinkin probably just like draw some
shapes on the screen represented in the GA racer will begin
and keep opening it consul in case you have
an issue and maybe add key listener so we can
certainly bring the G research that’s again remember remember dimensions dimensions
are weird but it seems like all the swing methods really like using dimensions your sex
life we got our are big black panel up on the screen and
i think im gonna conclude the video about right now if you have any questions or comments
put them below the video if you’re new to this channel I’m doing
on game development program restores two to three times per week so please
subscribe generate the videos I’ll see you next
time the new it

Leave a Reply

Your email address will not be published. Required fields are marked *