Hang tight while we fetch the video data and transcripts. This only takes a moment.
Connecting to YouTube player…
Fetching transcript data…
We’ll display the transcript, summary, and all view options as soon as everything loads.
Next steps
Loading transcript tools…
Java GUI 🖼️ | Bro Code | YouTubeToText
YouTube Transcript: Java GUI 🖼️
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
hey what's going on everybody it's your
bro here hope you're doing well
this is my new and improved java swing
tutorial series and in this video i'm
going to teach you guys how we can
create a
simple jframe that we can later add
components to
if you find this video helpful please
remember to like
comment and subscribe your support will
help keep this channel running
okay everybody so let's create a jframe
so a jframe is a gui window
to add components to we're not going to
be adding any components in this video
but in the next video we're going to cover
cover
labels so to begin let's create an
instance of a jframe
so jframe let's call this frame equals
new j frame so this
creates a frame for us an instance
of a frame however we'll need an import
so we'll add that at the top
import java x dot swing dot j frame
so if we were to run this it's actually
not visible
so we need to set the visibility to true
so we'll add that the end
frame dot set visible
and we're going to set this to true
so this will make frame
visible so we can actually see it now
however it is very small so
let's increase the size so we can do
that by saying
the name of the frame dot set
size so we can pass in a dimension
or a width and a height and this is in integers
integers
so let's say this frame will be 420 by
420 because 420 is a funny number
so this sets the
x dimension and
y dimension of our frame
and this should be visible now here's
our jframe
let's set some other things let's change
the title so we can do that by saying
frame dot set title and we can set this to
to
a string i'll call this
j frame title goes
here and this will display at the top
so set this to whatever you want your
title for your window to be
so this sets title of
frame now pay attention to this
so when we hit this x button in the
corner it's going to actually
hide our frame but not actually close
out of the program
so if you want to close out of the
program and exit
we're going to change a setting we're
going to use
frame dot set default close
operation and we're going to set this to jframe
jframe
dot exit on close
so when we hit that x button it's going
to exit out of
application and by default it's normally
hide on close so it appears that we
killed the application but it's still
running in the background
otherwise there is do nothing on close
and you can actually prevent somebody
from hitting the x button to close out
of the frame which is actually kind of
annoying but
that's how you can do that but let's set
this back to exit on close because we
want to exit out of the application
when we hit that x button now another
thing that we can do
is that we can resize our window
so we can actually prevent that so we're
going to say
frame dot set
resizable false
what this will do is prevent
frame from being resized
so we can no longer resize this even if
we tried
we can no longer make this full screen
either with the maximize button
so here's something else for you guys
how do we change the icon
for the top left of our frame window
normally it's the
java logo but we can actually change
that to something that suits our program better
better
so i'm actually going to use the logo
for my channel
and change the icon from the java logo
to my logo so if you want feel free to
pause the video and download an image
that you might want to use
here's my logo i'm going to change the
icon of my frame
to this logo instead of the default java logo
logo
so what i'm going to do is copy this go
to my project folder
and then paste it so then we're going to
create an
image icon out of this so image
then icon let's call this image just image
image
equals new image icon
and then we're going to list either the
file path or the file name
since this is within my project folder i
only have to list
the file name so this file name is logo.png
logo.png and then we're going to need
another import
so java x dot swing dot image icon at
the top
so this will create an image
icon and now what we're going to do
is set the image icon of the frame
so we'll say frame dot
set icon image
and within the parentheses of this
method here we're going to say image
dot get image
so this will change icon
of frame so then
if we tried this our image is now
at the top left of our frame in place of
the java logo that was there by default
pretty cool huh now let's change the
background color of our frame
so what we're going to do is that we're
going to say
frame dot get
content pain
we're going to have to do a little bit
of method chaining followed by
dot set background
and then you can place a color within
here so there's a few basic colors
and then we're going to need an import
as well so make sure to include this at
the top
java.awt.color so this will
change color of background
so now this window should be green
however you might not like some of the
default colors you can create a custom
color too
so within the set background method
we're going to say new
color and we have a few options we can place
place
some rgb values here or a hexadecimal
color value
so let's begin with some rgb values so all
all
zeros this is black
so the background is now black and this
is on the range from 0 to
255 with
255 for all three values is
just white so the first value is the
and you can see it's as bright red as
you can make it really
the second value is green so that's 255
and remember this is on a range of 0 to 255
255
so you can adjust the amount of red
green and blue that you want
so i'm just going to make up some random
numbers 123
50 250.
i have no idea what color this is so oh
i actually
really like that that's like a twitch purple
purple
so to say i think i'm keeping that
actually i'm going to remember this number
number
123 50 250. all right you can also place a
a
hexadecimal value here so you say
0x and then it's a
series of six values
so all zeroes would be black otherwise
all f's
would be white and if you don't believe
me i'll prove you wrong
so you can always go to google and look
up hexadecimal
color values and you can pick a color
that you want so
1 2 3 4 5 6 would be
this shade of blue which is actually
pretty sweet uh
otherwise you can really pick any color
you want and put that here
and the last thing that i got for you
guys today in this video is that
there are two i would say different ways
in which you can create a frame the
first is just to create an instance
of a frame and give it a name and then
you can change
all of the members and properties of
this frame by just saying the name of
the frame
dot and then whatever change you want to
make the other way
is that you can use a jframe as a parent class
class
to a child class so i'll show you how to
do that because i do this quite often in
this tutorial series
so what we're going to do is actually
create another class that's going to be
a child
class of jframe so go to your source folder
folder
then go to file new class and i'll call this
this
my frame so my frame
extends j frame this is the subclass
or child class and jframe is the parent class
class
also known as the super class then we're
going to need
this import at the top as well so the
other way in which we can create a jframe
jframe
i'm actually going to copy this
turn all of this into a comment because
we won't really need it right now
and then i'm going to create a
constructor for my frame
so this constructor is going to be
called when we create an instance
of my frame and i'm going to paste
everything within here however we're
going to replace
the name of our frame and take out that
line as well
so instead of saying frame dot set title
we're actually going to replace the word
frame with the word
this so an easy way that you can make
these changes is go to
edit find replace
and we're going to replace frame
so replace the word frame or whatever
else you called your frame
at this point with this and we're going
to create an
instance of the my frame class
so we'll do that here so we're going to say
say
my frame instead of jframe and let's
call this
my frame equals new my
frame and this will do the exact same thing
thing
as all of this code where it creates a
basically a duplicate of the frame we had
had
so you don't necessarily need to create a
a
name for this instance if you don't plan on
on
using this name for anything so one
thing that we can also do
is take out this portion of the code if
we don't really plan on using the name
or a name for your my frame you can just
say new my frame
and this works as well however if you
need to make some changes within
this class to your my frame you might
have to actually create a name for
it all right so that's the basics of
frames in java if you'd like a copy of
all this code i'll post all of this in
the comments down below
but yeah that's how you can create a
frame in java
hey you yeah i'm talking to you if you
learn something new
then you can help me help you in three
easy steps
by smashing that like button drop a
comment down below
and subscribe if you'd like to become a
fellow bro [Music]
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.