 Hello and welcome to the series of video lectures on the subject Java programming for third year IT students. I am Dr. Srichal Gajbar and in this video lecture we are going to understand the swing basics. At the end of this session you will be able to create a simple graphical user interface frame with different swing components or controls. So most of the swing components are based on the modernized version of the MVC architecture. Now the MVC architecture in this case stands for model view controller architecture. Now MVC is a very popular object oriented programming user interface decomposition that dates back to 1970s and as I mentioned earlier most of the swing components are based on this MVC architecture. Now let us see how they interact in this case. So the first component is a model. Now what is the model? The model is responsible for maintaining all aspects of the component state. Now in this case you can see the model here. For example the button pressed or not etc. So all this information will be stored inside a model. And the model here does not know its view and controller. However it does communicates indirectly to view and controller as the event notification. So that is why here you can see the dotted lines. This dotted line indicates that model communicates with view and controller indirectly through event notifications. The next component is view. What is view? The view determines the visual representation of the components model. This is a components look. For example the view displays the correct color of the component whether the component appears raised or lowered in case of a button etc. The view is responsible for keeping its on-screen representation updated. The output of the view is displayed on a computer monitor whereas you can see here the controller is connected to mouse and keyboard. The controller is responsible for determining whether the component should react to any input events from input devices such as keyboard or mouse. It determines what actions are performed when the component is used. The controller can receive messages from the view and indirect message from the model. Now what are the different advantages that are there because of the MVC architecture? The first advantage of MVC is multiple views using the same model. For example let's say you are displaying some employee data. So if there is a MVC then the same employee data can be represented using table or histogram. So basically the model will be the same but there will be different views. Then the MVC also provides the efficient modularity. The meaning is that it is possible to develop view and model in different environments such as developing push button in Java and the model data stored in visual basic. Then MVC also provides easier support for new types of clients. The meaning here is that to support new type of client we can simply write a view and controller for it and we can basically wire them to the existing model. So basically the model will be same. We can write a new view and controller for that particular client. So in the last video we have understood how to create a frame window. Window pane is nothing but a free area of a window where some text or components can be displayed. Now there are four types of window panes. The first is content pane where we usually add our components. Then there is a layered pane where we will add the component groups. Then there is a root pane where we are going to add the background components. And there is a class pane where we usually add the foreground components. So basically a frame window will have four types of panes. End pane, layered pane, root pane and class pane. So pause the video for two minutes and write down the answer of the given question. I hope you have written the answer. The correct answer is swing components are based on model view controller that is MVC architecture. Now let us create a Java Graphical User Interface application. Now in this application we are going to basically create a frame by using the JFrame class. Then to this JFrame class we are going to add a panel using the JPanel class. And to this panel we are going to add this Jtext field where you can basically type text and we are going to add one Jpattern also. So basically let us see how we can create them. Now as and when our application gets complex we are going to make use of classes which are available in swing as well as in the AWT package. So it is better idea to import all the classes of this swing as well as AWT packages. So that is why we will write import javax.swing.star. So .star will basically import all the classes interfaces which are available in the javax.swing package. Then we are going to write import java.awt.star. So basically we are also importing all the classes which are available in the java.awt package. Then we are going to write the class name. So class is so we are going to name it as demo app. So let me save this and I will save this using the same name demo app java. Now in this case let us write our public static void main method. We are first going to create a frame. So that is why we are going to write and then what we are going to do? Let us run this to check whether everything is proper. So javac demo app.java. So no problem. So java. So this is the first way application. So our frame is ready and if you close it it closes properly. And the next job is to add the panel to it. Now you can create a panel by using the jpanel class which is available in the javax.swing package. So here let us create an object of the jpanel class. So jpanel. Panel is the name of the object that I am giving, new jpanel and I will put everything as a default. So here we have created object of the panel class. Now we want to add this panel to our frame. We need to access the content pane of our frame. So for that purpose I am going to write container. So I need to create a reference of the container class. So container p is equals to and I need to call a method. So frame dot and the method is gate content pane. So this method frame dot gate content pane will access the content pane of this frame object and the type of that is nothing but a container. So for that we are going to create a reference of the container class. So container p is equal to frame dot gate content pane. Now once you have accessed the content pane object of a frame we are going to add the created panel to this content pane. So for that purpose we are going to write p dot add. Now let us run this. Now here the panel is added. Now you are not able to see it differentiate whether the panel is added or not. So in order to show the difference that we have actually added a panel let us change the background color of the panel to the green one. So what we will do here we will change the property of a panel. So we are going to do panel dot set background. In this case we are going to pass a constant of the color class. So color dot let us run it again. So the application is still running. So let us close it, clear the screen and let us compile it again. Now in this case you can see the background of the panel is now green. Now in this case we are going to add two component the text field and below that we are going to add a button. So let us do that. So in order to create a button we are going to create the object of the j button class. So j button btn is equals to nu j button. And here I will provide the button as a name as click me. Next we are going to add the object of the j text field class. So and here I pass the number of columns as 30. So once we have created these components j button and j text field we are going to add them to the panel. So we are going to write panel dot add and we are going to add the j text field first. So tf object of the j text field class and then we are going to add panel dot add we are going to add the button. So now let us compile and run this program. Now here you can see our application as desired. So this is the button with the name as click me. Nothing will happen because we have not added any event in this case. And here you can see the text field where you can basically type the content. So this is our application which we desired. This is the reference. Thank you very much.