GUI full graphical user Interfaces, meaning for the graphical UI. Also known as graphical user interface, GUI refers to the use of graphical display of computer operation user interface, for example, we click on the QQ icon, will pop up a QQ Login interface dialog box. This QQ icon can be called a graphical interface.
The three essential prerequisites for GUI programming are components, events,
Component:
Components are some basic graphical elements, including two types of components, such as the buttons we often use, text boxes, text fields, multi-select buttons, radio buttons, etc., the other is the container we often talk about, such as form, panel, etc., its role is mainly used to organize the interface components or units.
AWT ComponentsThe AWT component is a heavyweight component that relies on the GUI of the local operating system and lacks platform independence. However, the AWT components are simple and stable, compatible with any JDK version. The classes involved in AWT are generally in java.awt's packages and their sub-packages. The classes in java.awt are responsible for interacting with the local operating system, allowing the local operating system to display and manipulate components. the two core classes in AWT are: Container (container) and component (Class)
Component Class
The most basic component of the Java graphical user interface is the Component,component class and its subclasses that describe GUI elements (tags, buttons) that graphically display on the screen and interact with the user.
Container class
Used to organize components or units on an interface. There are two commonly used container (containers), one is the top-level window where the Window,window object represents a free berth, and the other is that the Panel object can accommodate other component objects, but cannot exist independently and must be added to other container. For example, window or applet.
Container it has a certain range and size, which is generally rectangular. Also has a certain position, this position can be divided into relative position and absolute position.
A container can contain other container,container that can be nested container, and when the container is displayed, the elements inside it are also out of hours, and when container is hidden or closed, the elements it contains are also hidden.
Relationship between component class and Container class
The Component object cannot be displayed independently and must be placed in a container object.
Container is a subclass of component, and the container subclass object can accommodate other component objects. Container objects can also be added to other container objects as component objects. Event events are action events triggered by a component, and different events in Java are handled by different listeners, components are event source objects, and listeners are primarily used to receive action events from event source objects and then handle them. Event Monitoring
Description: Objects generated during event implementation: events, event sources, listener events: an operation on the user interface, typically using a variety of input devices, such as a mouse, keyboard, and so on. Event Source: The component that generates the event, such as a click on a button is the event source listener: Contains the event handler, which is responsible for checking whether the event occurred and, if so, activates the event handler to process the listening process: When the event source object produces an event, it encapsulates the event's information and then sends it to the listener object, the listener registers an event listener with the event object, in order to allow the listener to check whether the event occurred, and then the event handler checks whether the event occurred and, if so, activates the event handler for processing. Import java.awt.*;
Import java.awt.event.*;
public class Tfactionevent {
public static void Main (String[]args) {
New Tfframe ();
}
}
Class Tfframe extends frame{
Tfframe () {
TextField tf=new TextField ();
Add (TF);
Tf.addactionlistener (New Tfactionlistener ());
Pack ();
SetVisible (TRUE);
}
}
Class Tfactionlistener implements actionlistener{
public void actionperformed (ActionEvent e) {
TextField tf= (TextField) E.getsource ();
System.out.println (Tf.gettext ());
}
}
Java GUI Programming (i)