Welcome to this lesson on Java applications, this is the second part of writing Java GUI applications or Java Windows applications. We talked about earlier how AWT and Swing components are related and again, you can see in this inheritance diagram here how we have our AWT components right here and then our Swing components are inheriting from our AWT components so these are all our Swing components here. No matter what, users interact with all of these components so users write in text fields or they click ''J'' buttons and so on. The Java components actually listen for user actions so a button click or text fields or the check of a checkbox, we can see here that in this case, the AddActionListener is being called on a button. Then when an action takes place, the action performed method is called and then we test on which component the action occurred. If it was the button, in this case then the code within the button if blocked is going to be executed. Before we go much further, let's talk a little bit about the layout of our frames and our Windows. Flow layout is the default Windows layout and new layouts are actually set in a layout code is ignored so you can see even if we're calling the SetBounds method here, if we have flow layout enabled then in this case, since we have commented out the set layout here, so we will automatically get the flow layout. The flow layout manages all of the components such as the text fields, buttons, the labels, the check boxes as you can see here we have checkboxes. We can see here that each checkbox is being lined up here automatically, so we have the soda one first, then the burger, then the fries and it's being added row by row, continuing to the next row as needed. The layout is not, at least the way that I like to build these applications, the layout is not being put together in a way that there's a lot of thought behind it, you don't have a lot of flexibility in building it, making it look the way you want it to look. Now, if we look here, on the next slide here, we are actually setting the layouts to null and then we are actually able then to call out the position of all of the components, so the developers can settle the positions. You can see here we set the layout here and set layout to null and that turns off the flow layout. The layouts can be called for a frame or for a panel, it doesn't matter which and once we set it to null, we're able to actually position all these components so you can see here these checkboxes and labels are now positioned by the actual code in the application. Additional Swing components such as radio buttons, button groups, combo boxes, image labels and message boxes, so we're going to talk a little bit about these. You can see here, we can directly interact with well, CB here stands for checkbox so you can see here some checkboxes and we can call an action listener right on any of these components. You can see here, checkbox 3, if it is checked here we have, we're calling it an action listener and we can see here the action performs if checkbox 3 is selected. We can turn an image label here, or you can set the visibility to true or false so essentially turning this image on and off. We can directly interact not only with the checkboxes but also the radio buttons and also the combo boxes here, and our image label will allow us to enable or display an image. There's also those pop-up message boxes that deliver some immediate message to the user, such as information or an error, maybe alerting of an error, sometimes they're called alert boxes. A button group, these are important because radio buttons need to work together. Checkboxes tend to be completely independent, you can have as many checkboxes as you have. Checked or unchecked, any combination of checked or unchecked. However with the radio buttons, only one is checked at a time and the way that we put these together so they're all working together, is something called the button group. Once we put all the radio buttons into a button group, only one radio button in that button group can be checked at a time. A combo box here in Swing is our drop down list of different options and we talked a little bit about our image label and again, we're going to see some more information on our message boxes. Our check boxes that can be checked or unchecked, or selected or unselected. We can see here that we are instantiating our check boxes and we're passing in a caption. In this case though, interestingly enough, the caption is defined somewhere else, somewhere earlier in this application. Our button here is where the action is being listened for. Nothing will necessarily happen when we make our selection here of each check boxes, we'll simply check them. However, when we click the button, this is where the action will take place, an evaluation of the state of the checkbox. Here, once our button is clicked, we have our action performed and we are checking to see or testing to see if the button was clicked. If so, that's true. We're going to look at our checkbox one. If it is selected, we're going to execute this code. Again, we have our try catches because we are, as IT professionals, we're validating if there could be an error and we want to handle any errors if possible. So the application is robust, smooth, and more friendly messages such as the one you see here, can be returned back to the user. You could see here, that in this case, we have some checks, but we don't have any quantities put in. Here we're actually testing here with this parse integer. If the parse integer, if this is not successful, we were returning the string. If this is null, the null is returned, but a null cannot be parsed to an integer. That introduces an error, we go into the catch block and we're able to send this message back to the user, reminding them that they need to enter quantity, in this case, it's going to be this combo box. Our radio button group and our radio buttons. Here are radio buttons here. We can see that we are instantiating our radio buttons and we're passing in, in this case, we're directly passing in a caption. You can see the captions right here. We're also declaring a button group. A button group allows all of these radio buttons to work together, so only one is selected at a time. We instantiate our button group and then we add each radio button to the button group as many as we need. Then they will all work together. Then when we are in our actions, when we're evaluating, what we're going to do is check to see which one is selected and then take action on. This is an example here, where we're taking action on whichever one is selected. In this case, Curb Side Pickup is selected. We can see here Curb Side Pickup. Our string getIt here will be set to curb side pickup. In this case, it's set to Delivery. We select Delivery, it unselects Curb Side Pickup. We're able then in this case, if it was curbside pickup, or delivery rather, it would come in here to Delivery. Here again, we are doing some testing of some conditions. We're taking this getIt string and then we're adding this getIt string here for formatting purposes. This gives us, in this case, what will be a delivery method. Then we have our combo boxes. A combo box is a very useful component. It allows users to avoid typing and free form data entry. The developers in control of what data the user can enter and the user enters the data by selection. It's a way of reducing errors. The way that we build our combo boxes is we started off with, in this case, we can see an array, and in this case it's a string array. Then we're able to pass the string array while we are instantiating our combo box. We want to at least initialize it to a member of the array. Arrays are zero index. So in this case, this is why we would see it initialized with the null value. Then here as we go through, our action is performed again, on this case, on this button. When this button is clicked, it's going to then test to see which of the check boxes are selected. In this case, a J check box is selected. So it's going to go through here again and retrieve the selected item from the combo box into this string, which [inaudible] SEL. It'll go through and do some parsing just to make sure that something that parsable of an integer was selected. We've already talked about these steps here. An image label is another useful item. Essentially with an image label, we're able to edit image to the label and we're able to make that image visible or invisible. In this case here, we have a checkbox and we're actually calling the listener on the checkbox. We're also defining here the image label. So we're instantiating an image icon, calling an image icon, and we're giving it a path to new Image. We generally try to be as relative as possible, even having it in the exact same directory from where the application is running. But in this case, just follow the steps. We are using this image icon for our new JLabel, which we're going Image label, setting the bounds for it, setting the icon. In this case, we're setting it to false. Then we can see here, we're directly calling the action on the checkbox. So when we click, we don't have to click anything when we check it. We won't have to click on anything else. We can see here, in the action performed, if the sea p3 is selected, we will set the image label visibility to true. If we deselect it, you can see the exclamation there. The image visibility is false. Message boxes or j option pains, are ways that we can deliver brief messages back to the users. Sometimes these are called alert boxes. So in JavaScript, alert boxes and in when other windows programming, they're also called alert boxes. So here we can return different message dialogues or we can return errors, we can return different icons. We can return simply just an information message like you see here. We can do yes, no, cancel combinations, which actually returns an integer for evaluation. So they're all options here that can be passed in. So we can change the look of these boxes and how the user will interact with them. So we can see here that we have in this condition here, where none of these checkboxes are selected, we send back a message, just strictly a pop-up message that says no items are selected, so and we immediately return so the user knows that he or she forgot to check something that needs to be checked. Then a little further down here, we're actually taking the processing information, building some strings and returning this whole string here and the string is formatted. So it's got the a separator here. We can see here this separator, the grand total. This is all formatted here. So that's why it looks the way it does. Put together, these message boxes are these Jay option pains. What we want to do here is make sure that we go through and we select the right message dialogues. So there are different options that we pass it. When we declare these, we can see the yes-no cancel options, which in this case returns an integer because we have to know what the user select the yes, no or cancel. You can also return back an error message. So we can see here as we are typing in this case, we can see we get some assistance from the IDE. We can see here, the option pane, we can see warning messages. Again, we can see the Yes option, No option, Cancel option. In this case here, if we want to know what the user selected, the yes-no cancel actually returns an integer. So we can see here, just to make it a little simpler, we declare an integer and on the j option, we call this as a constant. So this will return an integer. We can see here option button. Now we can take this whole J option pane here and pass it in right down here. But in this case, just to make a little simpler, will return our integer right here. Then we're going to set up an instantiated J option pane and show our confirmation dialog. We're going to put out the message that you see here and it's going to be a yes-no cancel. We can see here the integer that will be returned. Now, if we click yes, a zero is returned. If the user clicks, No one is returned at the user clicks cancel of two is returned. We can actually test, to see which integer was returned. We just go through a little example here. So on one Run, the user clicks. Yes, it has zeros returned. On the next Run, a user clicks and ''No'' one is returned and then a user and a subsequent Run user clicks ''Cancel'' and two is returned. So please go through all the steps in this lesson. Please complete the lab, please complete readings, and please complete the quiz. So we have a lab for an upcoming lab to work with all these components. So please complete the lab, please complete any readings and please complete the quiz.