Learn Java Game Development | Alexandru Rosu | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Learn Java Game Development

teacher avatar Alexandru Rosu, Technology matters

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

10 Lessons (1h 46m)
    • 1. Presentation

      1:09
    • 2. Application configuration process

      6:10
    • 3. Create a simple JPanel

      9:49
    • 4. Images JPanel in action

      11:24
    • 5. Swing Listeners and Spring Context

      9:20
    • 6. Build the letters JPanel

      13:20
    • 7. Create the panel to guess the word

      27:11
    • 8. Generate new game process

      5:04
    • 9. Spring Boot, MySQL and generate new words

      15:01
    • 10. Add a JMenu to our game

      7:38
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

35

Students

--

Projects

About This Class

Hi,

Under the following class I will define the flow that can be followed in order to create your first game using the Java programming language.

Please note that, in order to follow this class, you need to have some knowledge on:

  • Java language
  • Spring Boot Framework (application is developed by the support offered by Spring Boot framework)
  • MySQL relational database (know how to set it up under your local instance)

Under this class, I will provide a detailed explanation on the different components that were created as part of building the game.

We will see various Swing components in action such as:

  • JFrame
  • JPanel
  • JButton
  • JLabel
  • Button and Mouse listeners
  • and many more...

Notes (what you will learn if you take this class)

- code your first game

- create your first game in java

- develop for your Spring Boot based game

Meet Your Teacher

Teacher Profile Image

Alexandru Rosu

Technology matters

Teacher

Hi,

My name is Alex and I am happy to join skillshare as an teacher.

I have a bachelor degree in Computer Science and a Master Degree in Multi modal distributed virtual environments.

With a strong passion for programming, I enjoy finding solutions to various IT related problems.

My favorite programming language? I can tell you that it's Java, but I have also worked with other languages such as NodeJS, Angular, Typescript, Python, etc in my previous 10 years of experience.

Will be happy to share my knowledge and create great content for everybody who wants to join my classes.

Let's build awesome things together :)

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Presentation: Hey guys, and welcome to my course where we will build from scratch a complete guess. The world, also known as hangman game in Java, by using springboard MySQL in Java Swing technology. Under the following sections, you'll get to interact with various aspects of building things game, such as defining the ecosystem of working with Spring Boot framework, one of the most popular frameworks on the market. And also you will manage to create the app in a modular way, such as each feature is separated in a corresponding package. We will define several components as part of this game. But don't worry, Since I will show you exactly on how to make them interact with each other. Last but not least, since it's a handmade simulator, will lead to store somewhere the words for this will add the data under the MySQL relational database. So let's get started. 2. Application configuration process: The first step in our development process is to create a spring, both application. So I went toe start that spring that I wrote and the work here. You see that you have several options that you can choose the project type, the springboard abortion, Java language and now for the project meta data. We can set up a specific group and we will call it Come that hangman for the art effect. We'll name it game saying For them name on the description. We can call it Hangman Game simulator for the package name. We can go with calm and man game, the packaging jar and for the job. Orson, we choose the 11 version. We also have the ability toe add specific dependencies. But for now, we should not go into this direction, since those dependencies will be added in a manual way at a later point in the course so we can go to jury the project. Let's open this folder. Actually, let's extract a zip, you know, into a specific folder. Okay? And let's cut this folder under the projects over here. Of course, you can choose what they were location to perform. So now we have the option to import this made from project into our I d. Okay, and the next step will be to create the corresponding packages that will used as part of this course. So this is the base structure off the packages. So let's call this package contentment, Game guy and frame from the graphical user interface, a new package called Com Harmon, Game Guy and Listeners, where we will store our correspondent listeners. Another package for Menu I'm stating a new package now for the panels that will be added to the main frame off the application. So I'm trying here, toe a structure as much as possible this project into different sections. Let's create the package called Model. Another one for depository were store spring data JP a corresponding repository 1/4 service where we'll keep our main business logic service or for the service I am peel under the service will have an interface in under. The MPL will have the corresponding implementation and one less package for a deal over here. Next to the springboard start our dependency. We have the option toe add a new dependency here. Let's set up the Group I D or the Orc Spring Framework boot and the artifact I D will be a spring boot. Start our Web, since I have, since I actually want the don't get instance to run behind the scenes so the application will be up and running without in user in direction. So let's start the application now. We're choose Springboard App and the spring put application will start using a embedded Don't get instance, and we have the option to check this. Let's go to our bro sir, and type in local host 80 80 and we will see a default error page. 3. Create a simple JPanel: now, since we have the may know structure of the application setting place in terms off packages , we should start building our actual components. So the first step is to navigate under con hand man Game guy panels and great the simple Class. Unless call it empty panel. The first thing is to annotate this class with the components stereotype so that it will be a registered with the spring as a simple component and can be injected later in the corresponding frame. This class will be X will actually extend the Jay Powell. This is helpful for us in orderto create the actual panel as a separate component. Now let's add a simple constructor, and we have the a reference to the J panel using the keyword this and we want toe set the preference size to a specific dimension. 500 per 100. That's also said the background color off the panel toe black, and we can set up a simple layout for our panel and let's go with the grid layout two and a one. I stopped the initial law running off the application now, since we have this simple plan allowing simple panel in place we can go to the comb hangman Game guy frame and create the actual frame off our application that will keep all the panels. Okay, we can click on Finish Parton also for our hangman frame. We should annotate it with component so that it will be a picked up by the spring. This glass world or extended J frame J primi some class from the job, a swing package. And we have the option toe auto wire the empty panel once again. Since empty panel is a component, we can inject it directly here, and we're also create AH J panel called Main Panel. That's also add a comment, since this main panel will people all are important panels that would be added to the main J frame. So imagine that we will import All are created panels at that at them to the main panel, and this main panel will be added directly to the J frame. We also set up a simple constructor analysts greater method called create main guy and we'll need toe annotate it with the most construct so that this method will be automatically involved. We imported the job back sanitation package North little properly use the post, construct a notation, and now we will define some more specific properties for our mangy frame. We need to set up the bounds toe 170 1000 105 100. We're not allowed the user toe pretty size this J frame as an option. The next step will be a tow. Add a specific window listener toe this J frame. We're only two instances it Windows adapter. Let's remove this comments, and we need to implement the corresponding method called window closing and as a perimeter . This would receive the window event. And when the user will click on the X button in order to close this window, we're actually get rid off. The application will exit the application. A really small The resource is now we need to insensate the main panel and under the main panel, we're in it toe set the layout and for this case will use the border layout. And now we are able to at the empty panel under the main panel using the border layout south option. So this inter panel will be added in the bottom and we're also at the main panel toe the J from the main Jerry frame and set the J frame as visible through the corresponding user. Now let's start the application. Let's save the empty panel and you see that we received on error. Springer does not work well with the swing corresponding components, and you see the error here that is related to headless. In order to fix this, we need to navigate to the may know main corresponding method from our game application, and I removed the initial statement and we'll need to use the spring application builder Oh great on your object for for the spring application builder. And as an instance, we received the game application that class, and we need to set the headless for the builder as false and around this builder, and we are now ready toe start the application since the headless option was said to falls and you see here at the bottom Recep the empty panel and we also have the option to close the J frame 4. Images JPanel in action: now before starting toe build. Ah, next panel normalised the images panel. We need some images to play with, so I set up for you two images 14 smile and 14 said. And the first thing to note is that we need to create folder under the source May resources and let's call it images. Don't worry, I will provide you. Both are set and the smile images still work on this project with them. So this being said, let's create the next penalty normalised. So I set up a class called Images Panel. This class wouldn't need to be also annotated with a component so that it will be picked up by the Springer Container and same toe, the and dependable. We need to extend the J panel. Does he move this comment? We're in the to set up early stuff. G labels loss, college images list. This will be used in order to store our images now or create a simple constructor called images panel, of course, and the method that will be annotated with a post construct so that it will be invoked automatically by spring in order to set up all the properties for our images panel. The first thing we're bay to instance, she ate the images list as a nor racialised. I also set the preferred size too. 101 100 as a dimensional object for R J panel. Let's fix this. Since it's not called images, it's actually the images list. Okay, let's set the specific background caller for our family as white, and we will also set the specific layout as greatly out with the five rows and one column that's sit ups on space here. Now I would like to to a four loop from starting from zero 24 inclusive, so lets them five and we'll create or Jay label. Imagine that we need to store five images, so we create that some simple objects for RJ label. Let's also go to the com hangman game You till in Greater Simple Helper, since I would like to store some references to the tow, both smile and sad images under this help or class. So I undetected this class with component. Let's set up someone simple image icons, so this will be on image icon that will have a reference to the smile image, so we need to create an image icon and we'll use the helper class. Get class loader, get resource and if you recall, set up the image under the images. Smile J. P. G. And let's also do something similar with the Seth Image. New Image icon. The same process. Help or class get class loader. Get resource images Now said that Being G. So we have ah, or events to both. This image is, and now let's go to the images panel and over here as a perimeter toe the J label constructor, we can set the We can actually use the reference to the help or smile image, since by default or images will have ah, the smile of corresponding type said to them and get image. But you see that we recieve a narrow, so we need to somehow transform this reference to or no to a specific format that the G labour will actually be able to properly use. In order to do this, let's create a simple method that we return on image icon. Let's call it skill that we received the image source as a reference and basically for from this image source from this image, it will return on a image icon. We'll set the width and height to properties to 50. Another variable for the type on the type Will Bay Powerful image type and our Did you be. And now let's create don't know a buffered image called DST from the destination new buffer image that we received the with 50 hide 50 in the type as the type entire Did you be? We're in A to use the graphics to D and based on the buffered image destination will create , will involve the create graphics method. Now we will be able to draw an image from the graphics to the object and will be the source 00 the width height and this, and we're also need to invoke the dispose method on the graphic store chip. And as a final step, we can return the image icon from this method. So over here we just need toe use the scale method, and you see that the issue has been fixed and that Jay label will actually point toe image icon for the smile image, and we need to also add the image label toe the images list. It's format a bitter cold Okay, let's go back to the hand man frame. Since we already have this images panel in place, that's inject it using the auto wired connotation, private images, panel images panel and similar Toe Dome Empty panel. You can add it to the main panel, this main panel ad images panel, and we will use the border layout. As for East. So this was be stored in the right part off the screen, the started application, and you could see that the images panel has been set up. Let's close this so and stunts. Let's move this council to the bottom of the screen No. 5. Swing Listeners and Spring Context: before moving on and start. Oh, implement the third panel in all list. We're only to set up some specific components classes as part off our development process. So I went toe calm. Hangman game. It'll package and let's create the class called spring context. Click on Finish. We'll need toe annotate this class with component stereotype, and that's also other descriptive comment such as this component will be used toe. Also are the spring application context inside the non spring corresponding go class. You will see at a later point in this course how this ah class would be used so a spring context needs to implementer application context aware. We're also used the auto wired sanitation and let's add a variable aesthetic variable off type application context on Let's call it application context. Be sure toe imported from the spring for a more corresponding package, and we'll also need to override the set application context method. Since we implement the application context aware, this method receives the application context, patter, meta and throw, so beans exceptional exception type. I imported the veins exception. Now we'll use the spring context, that application context to be equal to the application context received as a perimeter in the set application context method. And let's also return the application context using our static method. And over here we're returning to the application context. Okay, let's move forward and work on the listeners that will be used in our application will have ah, mouser listener and also a bottom listener. So let's go under. Come hangman Game Guy listeners and create our most listener that we respond toe most events for our bottoms that will be created in our In our course. This most listener class needs to extend the most adopter. I set up a simple empty constructor or glass. Let's have the comment or the metal that will set up hand of the case when most enters a specific bottom. The method needs to be called most entered off type, void and receives off. Most event As a part of matter, we will need to get the the bottom that we selected actually the bottom that triggered this most event. When we enter on the bottom with the mouse, this event will be automatically generated. So if the bottom choosen is enabled and we went with the mouse over it toe basically hover the bottom. We need toe set, the background color as an effect. Let's sit there toe white so that the user knows on which bottom he he called work. Now let's add a new method that were handled the case. When mouse exits the lot, we need to call it most exited off type void. Of course, Cento the most centered. This receives a mouse event, and we need to check if the choosing bottom is enabled. We'll set a specific background color toe this bottle or so Okay, we said the background color. Let's create the new class called bottom listener So this bottom listener class needs to implement. Ah, actually, listener that's also at the methadone is to be implemented action perform that receives an action event. E you need to get the cordon bottom that we collect on using the same process he gets source. We're simulator fact that we don't want the bottom Toby selected once again. So we disable it and also said the background color to green. We're also need to get the bottom corresponding letter since each bottom will have a letter well, though this using the get text Pachauri off zero. This will effect get us the first and only existing letter toe that bottom that is added to that bottom. And now, if you recall the application context, the spring context class will be used here. Toe retrieve the application context. And at the letter point in this chapter, you'll see once we set up all the buttons in place, how will be able to use it? Is application context inside our module? 6. Build the letters JPanel: Now we're ready to create Arthur Panel in the list. So let's navigato Hangman game going Panels corresponding package in Creator letter. Spanish class. We should follow the similar approach toe. Annotate this class with the component stereotype so that it will be picked up by springboard. This class will need to extend a J panel swing component. Now we're going to create the specific map that will keep the key value pairs off letter and corresponding bottom, since we'll try to simulate the entire keyboard off our desktop computer or laptop computer depends on users case. So I'm creating Ah, simple map, with the key being a string and the value being the corresponding Jay bottom and we'll call it letters Map now for the letters. Parent constructor. We're set a simple layout off grid layout where we'll use, um free and zero corresponding greatly off structure will set in place. Ah, create panel method that is annotated with post construct so that this method will be automatically involved by spring and we'll start to define least offer corresponding rose from our keyboard. So the first list will contain all the letters from Q toe. Be inclusive. So I'm adding here all the letters from the two Tau Bay on our Keyport. Let's go with a similar approach for the second road and we'll set up letters from a toe. L Let's recall that all letters are uppercase J okay. And also l Let's set in place the last room from Z tow em. So our is as list z x, c v be and and the final letter M So we define free list off strings that will keep track or far, three rows from our keyboard and include all the letters. Now we should add the descriptive comment. So Charles Cordage letter in the list we need to create Ah, corresponding bottom. Now, I would like to set up a method that will create a J panel 42 list off letters that will be set this perimeter. So we're received each off the three letters and based on that, let on those letters we're creating corresponding panel and that panel will have ah, a set off bottoms that will match those those letters. So I am creating hero letters panel. This will act as an intermediate panel. We want to create ah bottom listener corresponding instants And that's also where the most listener new mouse is sooner and now forage letter in the list. We want to create the bottom and the corresponding data should be mapped to it. So let's go iteration on the letters list that is received US Parliamentary toe this Method and Forage letter. We will try to create the bottom that we received as parliamentary for the constructor. The letter. We want to create some properties for this bottom, such as said preferred size and also set the background the color 100. Okay, and now we should at the action listener such as this bottom willow respond to specific events and also most listener so that this bottom will be able to respond to mouse events, one mile center and most exit. And let's also other specific formed toe this bottom we could great hero variable. Let's call it phoned and we will instance he ate a new phone, but we should not forget about the type. So this is fond. The variable name formed and for the front will use bold. And then the six. Let's use the helper class for this, and that's his ah constant variable. Her performed. So we said the phone for our bottom and now for the letter bottom. In fact, let's ah, at the letter bottom toe, the letters panel. And we need to also added toe the letters map. So the letter will be the key, and the letter bottom will be the corresponding value so that we're keep all the buttons in one place that is letters map. And since we created intermediate Panel, we need to return it. And under the create panel method, we need doing folk the creator letter spaniel for each off our free lists. So let's greater variable called U P Panel that we return a panel off bottoms from the Kewpie list. Same for the second list from a toe l and also for the Turk list. Zito him. So we have free panels of the fire and we'll add this free intermediate panels toe the main letters panel using the de Cem cured. Since it has a reference to the main panel, let's remove these spaces and now we have the letters panel in place. But we'll also want to have the centering getter metals for our letters map that will keep our reference toe all our bottoms that were added to the letters panel. So this is the get method on Let's also at the sit metal. But let's do this manual listen. So Spring told suit, I d can do this automatically, but we can write his town from our own. So this letters map equals letter. Smell on. Let's go to the hangman frame that let's inject the letters panel. We'll use the auto wired a notation private. Let our spaniel let them span. Hope it's the variable. And over here we need toe Add the letters panel toe the main panel. But this time we'll use the border layout that center. So that will add this panel in the center of our screen and let's start application and you can see the panel in place. Also, the most listener is in place. You see that when I have our bottom, the color has changed. Also, the action listener is in place. When I click on the bottom, the bottom is changed to green 7. Create the panel to guess the word: unearth this video or great our fourth panel from our list off panels. So let's not be gato our panel's package and create a new class. This will be called Worth Panel. We're annotate this class with the component spring stereotype, and we'll also need to extends the J panel class. That's also add a default serial verse in your I. D. We're going to set up a new variable that will be a list off Jay Bottom, and we'll call it generated work list so that each letter from are generated. Ward. We're map toe, a specific bottom that will be added to this list a new variable called Generated Ward that will keep our corresponding journey. That work and the number off tents that the user try to guess the world under this J panel class were nieto reference to the letters panel. So we're injected also another reference to the images panel. Oh, inject both off them using the auto wire, a notation I have created the simple constructor and over here will set specific panel properties added the set lay out as a simple floor layout, the preferred size for our panel only to set the background color to black, and now we'll annotate a new method with a post construct so that it will be automatically involved by the spring spring container. And this method will creator Tapout. So far, we will need to instance it their generator, the world with the default work. Since we don't have anything in place that will journey it automatically and in a random fashion words. So we'll go with something simple at this stage. So the jury that work with the game let's also incensing the jury that word list as in your A list and the number off attempts should be zero since we just started the game. Now, since we have ah, warning place, even if it's the default game work, we need to get the force and last letters from it. So this will be a charge specific variables. So for the first letter in world well extracted from the jury Third World that char it off zero and for the last letter and world, we'll get the jury that worth char at turreted world that length minus one. So now we have both the first and last letter in the world, and we'll need to reiterate over the journey Third World and create a bottom for each letter in the generated world. No final G button. Let's call it L Be is instant ated to a new G Pothen and by default we'll use that sign to simulate. That letter is not shown to the user. Well, said the bottom preferred size and also the bottom corresponding phone. Also, let's set the background color, toe white and do not enable it. It should be disabled by default so that it will not respond to any public events or most events will add is bottom toe the journey to the world list and also to the corresponding panel. Now, since we have the first and last letters exactly from the journey toward war, we need toe also show them in to the graphical user interface to the user since, as you know, we're doing ah, hangman simulation and the first and last letters off the world's should off the world should be exposed to you, the user. So I exposed the first letter and also let's expose the last letter to the user using the set text at the Now we need to enter it over the generated ward using a for loop. So for and I called zero i Lord injure net of the world length minus one, I plus plus and need to get it. It's a letter from the world that's also add a comment here, and what we're trying to do here is to Expos the Cordant letter to the user if the current letter matches the first letter from the generated world or the last letter from the generator work. So if court on the letter equals toe forced letter or cordant letter equals So the last letter we need toe get the generated war list. The corresponding go bought a reference and said the text. So the according to a letter, Okay, and now we need toe disable the letters that are initially exposed in the world, the that we generated. So in this way, we need to disable the first and last letters from the letters panel. Since they are already exposed to the user and the user should not be ableto click on them . So lets navigate to the letters panel and create a method here. Let's call it disable default letters and this method sure received the first letter in In World and also the or less letter in world. So let's create some strings based on the charts that we received the experimenters for the first letter and one for the last letter. Okay, and now we should disable the first letter. We need to get the reference to the fourth letter in World Parton. And for this, if you recall, we have the letters map that has references toe all our bottoms and we'll get the corresponding bottom using the first letter that upper case. So based on the letters map key will be able to extract the corresponding J button value. And we need to basically disabled this bottom and also set the background color to green simulated in a way for the user. And a similar approach should be follow for the last letter that we receive a spare a mentor for this method. So we were greater last letter in word bottom and from the letters map, we're get ah, last letter that Cooper case. Let's fix this. Okay, so we have the corresponding Jay bottom value and we need to disable it and also set the background color to green So let's do this, said Background Color Marine. And that's basically it. So let's go back to the world panel and invoked that method. So we have the letter spaniel reference that we injected earlier in this component. Let's call the disabled letter spaniel using the first letter in word and last letter in world. And now you're sure to turn the the panel that we created from this method as a next step, we need the method that will check you for selected. The letter is present in the jury that work, for example, when we will select the letter from the letter spaniel, we need to check it if it's present Inter generated world or not, and based on this will do something. So let's your set up Bullen Vallat letter found by default will be false and it there it over the generated world. We need to get the cordant letter on. The jury could work that Charlotte Well, fine. And we need to check the Cordant letter match is the letter that we, uh, selected and, if so, well invoked, the journey to the world list that kit off. I set text string value off letter So we're exposed The selected letter Since it's found in the journey Third World. So the selected letter will be exposed to user simulating the fact that he was able to find the letter. And since the user was able to find the letter, maybe we're on the case that the entire world has been found. So if the letter was found, however, we should not forget to change the letter found We're to Okay, So if the letter was found and we're also neither method to completed world to see if all the letters from the generative world were found. So let's implement this check completed world a simple method. So let's have a common check if or letters in the world have been found. So this is a private method check completed world and we will need the mechanisms toe figure out if all of the the letters from the world have been found. And in order to do this, if we have at least one off that symbols that similarly that the letter is not shown to the user, it means that the world it's not completed. So let's go do a search. How many? How many letters with that symbol we have in the journey that word left so number off letters found were extract from the journey to work list will so stream filter. And for each button we check that the bottom text it's equals toe that symbol into account . And if number off letters found greater than zero, it means that the world is not completed. But in fact, let's changes variable toe number off letters not found since its more descriptive. And if all the letters were found, we're already turned to. So going back to this statement if letters found, if letter found and completed world, we're need to involved the letter spaniel and get the letters map and for each you a letter in the letters map, please recall the keys are strings and values are G. Parton's. So for each bottom, well disabled it so that a user will not be able to click on any bottle in the panel anymore. And also, we should the show a pop up message using the J option pain show message dialogue, and let's inform the user that he was able to find the world in this case and less congratulating and has gone the else case. If letter found it's not true, so the user was not able to indentified or letter. We need to simulate this in the graphical user interface. So if you recall the list off images, we need to update on image reference from smile toe set. So we'll do this using the images panel and on the images panel, we need the reference to the images list. So only toe great the getter matter for this under the images panel, who have a reverence once again toe those five images that are used to similarly five possible attempts toe the user to get the entire world. So this were returned the images list and let's also at the sitter method. For this, set them in just list that were a civil list of J or J label. And this image is list equals images list. So going back to the world panel, we have access now to the get images list, and we'll get the according toa attempt. Please recall that the number of attempts is zero. When we stopped the game and we'll set the I can't were in fact changed icon from default smile image toe sad image. We're also increased the number off attempts And since we increased the number off attempts , we should also check here for we reach the moxie Mo more a lot of the times. So in this case, the maximum number off her attempts is equal to the images panel. Get images list size in our case. So five So if so, Well, it right over the get the letters map from the letters panel using the same approach described earlier. And we'll disable all bottoms in order to this allowed the user toe click on any bottles left. And we were also informed the user that he was not able to find the world meaning that he lost the game So the world Waas jury could work. Okay, so far, so good. This looks good. And if you recall, we set up here Ah, check letter method. But we don't call it actually, but we have on action listener for each or off our bottoms. And now under the bottom listener, we need to invoke that toe check letter method using the spring context class that we defined earlier. So we need to get the instance off the work panel. Since you see that the bottom listener is not a spring component and the world panel is the spring component, and using the spring context class will be able to properly invoke the, um, the method from the Worldpanel using this bottom listener. So you see the war panel check letter off leather. So now we would also be able to evoke Springer corresponding beans from a component that is not associated to the spring container. The last step will be to auto wire the were panel under the Henman frame and add it in the main panel under the north section. So let's do this. Let's also start the application now. We saved the world panel and you see, by default we have all panels in place and that default game world. You see that the what teams are in place from, Ah, a smile image, Sammy said. Image has been updated. The images panel 8. Generate new game process: we have to give me police, but it seems that we don't have any option to regenerate the game once we finish it with successful failure. So let's work on this. We need to work on the banners and for the empty panel. Don't need to do anything since is just an anti panel. But starting from the images panel, we need to create a way toe, regenerate the components on the screen. So let's set up a simple method, a public void, clear method and under this method will forced remove all the components for from the images panel and also very invoked the create panel method that will basically create all components and add them to the panel. Let's follow the same thing for the letter spaniel. So public voice clear this really move all. And let's revoke the create panel method and the same thing for the world panel. Public voice clear their city move all and the this great battle. So we now need away toe actually call all these free metals from the images panel letters panel and Worldpanel. So let's go on the hangman frame and at the bottom here will create, but I would avoid clear panels method. And if you recall, the hangman frame, has references toe all our panels and will invoke the clear method for letter spaniel worth panel and images panel. And we'll also needle method that will be called New Game. And under this method were forced. Dispose the Gordon J Frame. We need to get the X and why core tenets for Mara according to J. Frame position. And we'll also need to evoke the clear panels method so that we're clear and regenerate the panels. Once we've done that, we will set the location for our J frame and set it back toe be visible to the user with all the panels being regenerated in a correct way. Now we need to somehow involved this hand man frame new game method and will go under the Worth panel and happen instance to the Henman frame. This is a component so it can be injected, so we have to locations where we can generate this new game. In the case that the user has ah found the world and also in the case that the user was not able to find the words. Now everything should be in place and we have the option to Ruggeri the components basically toe we started the game. You see that the game has been no restarted automatically and all panels or a generated with success. 9. Spring Boot, MySQL and generate new words: Under this video, I would like to implement a mechanism that will allow us to extract random words from a database instead off using the default game world each and every time. So as a first step, we need to go under bomb that XML. And over here we need toe add some specific dependencies. So the fourth dependency, we'll have the Group I D or Spring framework that put And for the artifact i d. Spring Boat Starter data, G P. A. And now the second dependency. We'll have the group I d buy Skrill. And for the artifact I d. We need to set up the my school connector Java. So since we have this dependency in place, we need to go under Com Hammond game model package and create a simple class. Let's call it worth. So this class will act as ah GP the GP ao entity and would allow us toe interact with the database. So let's annotate it with the entity. Be sure toe use the Djelic Persistence Entity package and let's also adul table name as being the words well now need to set up a specific variable that will act as a primary key for our words stable. So we annotated it with the I D and the generate value. We're use, ah, generation type strategy as the identity. So let's that is now let's have the private long i d Variable and I would like to also set up private the string value. But first, let's are notated with column Land 16 and unique troops. Well, now add the probably constructor, a default constructor at this require for GBH entities. And let's use the I D to generate the getters and setters for our value field. Okay, next toe step is toe. Create the corresponding war, the report story. So this is related to our spring date, our g p A. So this needs to be annotated with the repository stereotype. And of course, it should extend the JPL repository and those perimeters. We need to set up the model class and the type off the primary key in our case, long and for the motor class off course, the world class. The next step will be to create service for our interaction with the business logic and our GP entity. So let's call this service World Service on. Let's sit atop on the comb hand man game service package. So let's change it. Owen interface and well defined two methods. One that will store a list off wards into the database when the application will run. Forced time and another method is to extract a random words from the database. So we'll need the concrete class implementation to actually implement this medals. So I created the World Service. I'm peel and annotated with service serial type, and this class implements though ward service interface. That's also at a unimplemented method so far, and that's also inject were the repository and for the list off words are already prepared for you. A list off 1000 words that will be stored toe the database so just can copy Paste this without writing them down. You see, there are many words that you can play with, and we need the mechanisms to actually store this list off words so under or safe that are in the B method will force check if the or depository count method return. Zero. This means that we don't have any word starts off hard in the database. We'll split the world list in tow. Honore separated by comma off course, and we're iterating over this. Words are a and save each worth in tow. The database using the war depository save method. So for this, let's greater simple constructor that receives the values perimeter. So this value equals value, and they should fix our problem, were stored directly award into the my School relational database. Let's move now to the get random world method. And for this, let's go to the war reports story and set up a specific method. So this were it or no work and let's call it find random work and we will use the query specific connotation and was select from Let's call our database hangman. Since the game in the game is Hangman and the evoked the Hangman Words Order by Rand Limit one and negative query should be set to true. So this will extract a random words from our hand man that the base that were configured later and from the word stable that we configured earlier in the world corresponding go Montel class. So going back to the World Service I appeal. Let's use the new newly created method from the world repository. So we're depository. Find random Worth. And let's retrieve the string value using the get value method. Now, since we have this two methods in place, really the way toe actually involved them. So for the first method, let's go to the game application. And over here, when the application will start, we will force inject, though corresponding service is in the auto wire annotation. And, of course, using the post construct method, Spring will automatically invoke this method. And at this stage, loves do a save data in the B call from the World Service. In this way, all words will be stored into the database. Now we need the way too invoked this get random word method and the if you recall on the Worldpanel we set by default that game as being the generated work and we need to change this. So let's ah, auto wire the World service in stones and instead off using the game text over here, let's use the word service, get random word method. So each and every time were juried. This panel, a new world will be extracted from the database. Now an important step is to set specific properties under our application properties, so far so that spring will be able to communicate with The mice will database. So we'll set the spring that all sorts driver class name. Ask the class name that corresponds to the my school law. Instance, we need to set the spring that us who you are So this u R L matches though my school instance that we set up locally and connects toe hangman database that will create for the spring that Assad's user name. We have the my school instance user name said to root in the past Work said to pass work off course. This depends on your my school. Instance, we will show the S girls that are generated in the logs and we'll use the D. V l Auto update in terms off possible changes that will do to the world model class Toby automatically store under the my school. Oh, corresponding instance. Now let's set the mice will dialect, sorg, hibernate dialect and let's store the file. My school a school 57 dialect. No, I went to my my school instance. And all you need to do is create a simple database called hand man one time only, And let's ah start the application on Let's look at the logs. You see that all words are being inserted. This process happens only one time and you see that already we have, ah, random world expected from the database in the graphical user interface. We can also review the fact that awards have been in certain toe the database using Go come from the or stable and you see 1000 wards. And now the game works much smoother in terms off, being able to endure it. Random words each and every time you see long words, short words and so on. 10. Add a JMenu to our game: in this video, I would like toa adoption to provide the menu for our graphical user interface. So let's close the corn the instance off the application and under Com Herman Game Guy menu . Let's create a simple class called menu. This class will be annotated with the component spring stereotype should extend the J menu bar. This is a component from our job back swing package. Now I need toe up a wire. The Herman frame main component. Let's fix this any more than Komites, our great ah constructor for many class. And after this, we'll set up in place. Ah, create menu method and under our constructor, let's call this create menu method. So under this newly created method, were forced. Define ah J menu called Options Menu, and we'll store the option strings options string next to it. And now let's create some simple oh menu items that will be added to the options menu. So for the option, one will have the possibility to generate the world, and for the second option, we'll have the use case toe exit, the application. So this is an alternative way off. Pressing on the export in now I would like Toa add also key listeners to R J menu items. So control plus N for the new game option and control plus e for the exit option. So let's do this. So Option one. When you do involved the set accelerator and the experimenter, we need to set the keystroke, get keystroke and key. Event that very key and and and we need toe at the action event as control mask, similar for the option to off your menu. Set Accelerator will still use the key stroke, and now we'll use the key event. We toe e an action event. Same thing. Control mask. Really toe Implement the business logic four. Our options So we'll add action listeners for both off them. So for the option one or the jury toward, we're only to implement the action, perform method and receives on action Event E. And over here we use the instance from the Hangman game and evoked and you came and for the option to, we'll add on actually sinner same ah method signature action performed action event e aspire aumentar and this time will exit the application. Now we need to at both option one and option to the options menu and add this options menu to the main J manual component that this glass extends. In order to properly use these menu were you need to injected under the German frame. So let's do this early to fourth used the auto wired annotation private menu menu seen. So our class is called in this way and over here will involved the this said Jay Menu Bar and for the battle matter will use the menu. Now we will start the application, and you can see that the options menu is present with two different options. Jared Ward and Exit oppressed on the generate world. A new world has been generated off course, and you have also the option to use keystrokes. Let's use them for the exit option.