Using the Abstract Window Toolkit to Implement Java Graphical Interface Design | The Concept of Components


theme: channing-cyan

highlight: a11y-dark

Keep creating and accelerate growth! This is the 18th day that I have participated in the "Nuggets Daily New Plan·October Update Challenge", click to view event details

AWT

Abstract Window Toolkit (AWT) is a set of tools for building graphical user interfaces provided by API for Java programs. In java. The awt package provides basic GUI design tools for Java programs. We need to figure out components, containers and layout managers.

  • GUI: Graphic User Interface

components

The most basic component of a Java graphical user interface is a component, which is an object that is displayed on the screen graphically and can interact with the user. For example: buttons, labels, etc. Components cannot be displayed independently. Components must be placed in a certain container before they can be displayed.

Component

The class java.awt.Component is the parent class of many components, which encapsulates the common methods and properties of the components. - For example: graphic component objects, size, display position, foreground and background colors, borders, visibility... - Code example: java /* 与颜色有关 */ public void setBackground(Color bc) //设置背景色 public void setForeground(Color fc) //设置前景色 public void getBackground(Color gbc) //获取背景色 public void getBackground(Color gfc) //获取前景色 ColorModel getColorModel() //获取用于在输出设备上显示组件的ColorModel实例 The constructor public Color(int red, int green, int bule) of the Color class creates an object. Its three basic colors range from 0 to 255. Different colors can be displayed according to different values. For details, see RGB . For commonly used colors, the Color class also provides some constants. Simply enter the English name of the color. For example: Color.red

```java /* Related to fonts*/ public void setFont(Font font) //Set the font public void getFont(Font font) //Get the font FontMetrics getFontMetrics(Font font) //Get the font specifications of the specified font

/* Related to size and position*/ public void setSize(int w,int h) //Set the size of the component public void setLocation(int x,int y) //Set the position of the component in the container public Dimension getSize() // Return the size of the component //···· ```

Guess you like

Origin blog.csdn.net/y943711797/article/details/132974419