课程: Learning Java Swing

Learn about Swing

- [Instructor] Learn about swing. The Swing API, or application programming interface, can be used to create graphical user interface applications. In Java, such as forms, it is often referred to as a widget toolkit for Java. The components are used with the JFC, or the Java Foundation Classes. The Swing API contains an extensive list of gooey components, or a component represents an item on the page, such as a button or a text box, or even a checkbox or a label. Swing components are often used in a Model-View-Controller architecture, you might have heard of this as an MVC architecture. The graphical user interface is made up of three parts. The user interface elements or components such as a button, a text field, a label, or even a menu. Next, we have the layouts. Swing provides several layouts that control the placement of your components. And finally, we have the behavior. The behavior are events that occur when the user interacts with the UI element. When the user clicks a button, when they type into a text field. All Swing applications use a system of containers. The top-level container can be a JFrame, a JDialogue, or even a JApplet. Once we establish our top-level container, we can build a hierarchy of components. Think of this top-level component as an empty picture frame. Before we start painting, we need to add a canvas. In this case, the canvas is what we call a content pane, which is usually a JPanel. So we add the pane to the canvas. We can use one pane for our entire canvas, or maybe we want to create a type of collage with several panes put together to be our canvas. Remember, the frame is used to determine the size of our window, but it does not actually contain the individual components. They must be added through a panel. To start programming a graphical user interface application in Java, we have two choices. We can use an IDE that contains a WYSIWYG editor, where WYSIWYG stands for what you see is what you get. Or we can add the components directly through the code. Each option has its benefits and drawbacks, but I will say that the GUI editor makes arranging our components much, much easier. On the bad side, it does add a lot of code behind the scenes making it difficult to change if you're not familiar with each component. By using Java, you have a system that is very flexible and runs on all platforms. By adding a graphical user interface, it allows your application to interact with the end users. Maybe your application is a front-end for a data entry system, or maybe you just want to create a front-end for a contact list. Java and Swing are here to help. Java Swing creates your GUI, your graphical user interface, and then the information can be stored in a database, a text file, or some other type of data storage.

内容