Welcome to this next lesson on writing Java applications. This is writing Java GUI applications. I'm sure you're very familiar with a GUI. It's a graphical user interface. They're the little windows that we interact with that largely support event-driven programming. They are of high user experience and they allow for textboxes, wizards, button clicks. The user's interaction is with rich objects, images, menus, pick lists, objects such as that. As IT professionals, the good news is, a lot of the programming of the event-driven and GUI programming is very very similar to what you've done in of.NET, C, C++. Java has two sets of class libraries for building GUI applications. One is called the Abstract Windows Toolkit or AWT, and another is called Swing. Both AWT and Swing are part of the Java Foundation Classes. AWT was the first Java GUI toolkit, and it provides a basic set of graphical components and the look and feel is always the same. Swing is a later edition. It offers advantages over AWT. One major difference is look and feel from Swing is consistency across platforms. It can even take on its own look and feel, and also components load faster than they do in AWT. Swing libraries are platform independent. Swing components are lightweight and they take advantage of the libraries and the operating environment. Swing provides a richer set of components such as tables, scroll panes, color choosers, and so on. Swing also follows the Model-View-Controller. The model-view-controller is a design pattern commonly used for developing user interfaces. Swing can actually take on the look and feel of different operating systems, and allow you to have consistency. The Swing components. Here is the object hierarchy. We can see here the components, the frames, the dialogs, the text boxes, combo boxes, the labels, the menu bars, the buttons. We can see them all in here in the object hierarchy for Swing. You can see here there's two different looks and feels. This is the type of a forms and windows that you can get. We have the text fields, we have the labels, we have the buttons again, we have the title bars, we can close our windows, minimize, we have the icons, the buttons again, so Swing is able to provide a lot richer interface for your users. For AWT, here's the object hierarchy. There's also panels, there's also frames, dialogs, text fields, labels of buttons, and more. If we take a look here, here's AWT, very, very similar in look and feel, but again, it has the labels, the text fields, the buttons, and users obviously interact with them the same way they would with these objects built from any language. For the most part, you will be able to get very familiar with this because the way that we actually develop these applications is also very, very similar to C++, C Sharp, or the other.NET languages, or C. With all programming languages, GUI programming is based on events. It's called event driven program, so events are your clicks, your set text, your enter texts, your checks, your selects. In Java, actions detect events and then run the response. Actions are part of the AWT class libraries, so you will notice that even in Swing applications we are importing the AWT class library because the events are part of the AWT class libraries, so Swing actually borrows the events from the AWT class library. Then action listeners actually hold on the components such as buttons. Action events are passed to the methods that respond to the action listener. We can actually see here there is a button right here called B and we add an action listener and we say that it is a new action listener, and then when an action is performed, it is this event here which will actually set the text for a text field. This is a text field here and when the button is clicked, we'll see here the action is set. This action will run and whatever is part of or the commands that are part of this action performed method, things like set text will take place, so an action listener is passed within a button and it will call a method where an action event is passed and the action event method will act to update one or more components and there could be more than this. Now, the click event on the button called the set text action on the text field. We can see here that we create a text field. Again, it's called mytf and in the text field and then we can give it a location and then we create another button B and we also give it a location. You can see here B, we call the action listener method and pass in action listener. Then when the event actually happens, the action event then we'll again set the text. We could see here that we have the button and when the click event happens, it will set the text here of this text field to, welcome to this Java AWT lesson. Whether you're using AWT, whether using Swing, whether you're using C, whether you're using C++ or whether using dot net, for the most part, it is the same set of steps, the same types of algorithm. It's just, the syntax is different. Again, we can see here that many types of events can happen as part of an action. In this case, that not only is the text set of a text field but we're also able to call a method. If we look here, what we are doing is we have a class called AWT listener example. We instantiate the class and we call it ALA and then, there is a method that's part of ALE hold of frame frmText, and what this does is it gets the current date and it returns the current date as a string. Then we can see here when we click on the button, the action listener and the event will set the text but it will also go in and call this method, so, we're calling frmText, which is right here from the ALE class. Then we are getting back that date string. Then down here we are combining the welcome a Java AWT lesson with the date, so you can see here. We can not only operate on objects, but we can also call different methods and submit different types of data. Now, when they're often, there's going to be more than one button. The previous examples we looked at, and a lot of examples that you looked at these beginner examples is always one button. But we'll always have just one action performed method. What we need to do is we have to test for which button is clicked. You can see in this case, we use a very special e. e is the action event and we call getSource on it, and we cast it as a JButton, and we return it back to this variable src, then we call getActionCommand equals on src. In this case, it's just the caption on the button, but it's looking for the caption. That's most likely always going to be unique. If it's not going to be unique, we'll have to look for a different method. But in this case, whichever button is true, it will test which button was clicked, and whichever one was clicked, it will execute the code in that if block. We're using here a set of if and else if blocks to operate. Depending on which button is clicked, different actions will be carried out. Again, we can see over here, we are again getting the source for a JButton. If we have the find my IP in this example, we enter a website domain and we click this "Find IP" button and it will return the IP address of that domain. So ibm.com, this is the IP address if we click that button. Then there's also the List It button. What the List It button it does is it updates a text area here. So every time we want a list of what sites that we were looking for the IP address on, we are able to click this button and it will add to the list. Finally, we can use this Clear button. When we click the Clear, it will obviously come down, find that the ActionCommand equals clear, and it will do the setText on the text area, and the labels in the text field, it'll all set it to null. This is one example, there are other ways to do this. One example of how we will handle multiple buttons while we are building our Java GUI applications. In the next lesson, we're also going to look at actions performed on other types of objects. In this case, these are checkboxes. We can see here that when checkboxes are selected, there is going to be a update in the space of a label, so we'll set the text of the label. Again, action performed same as with the button. If there are other types of action events that we can use as well, we'll take a look at them, maybe take a look at a brief example. But as you can see here, it is very, very similar to what we did for the JButtons. This is also very, very similar to.NET, C, and C++ the way that these types of actions are performed. Thank you for watching this lesson, viewing this lesson, please complete the lab and please complete the readings and the quiz. Thank you.