java awt_Java AWT简介

java awt

Java AWT简介 (Introduction to Java AWT)

Java AWT (Abstract Window Toolkit) package is a library used for designing graphical user interfaces.

Java AWT(抽象窗口工具包)软件包是用于设计图形用户界面的库。

It contains classes for placing various user intractable components and graphics. However, the components of this class are platform dependent. They are heavy and rely on the OS for their functioning.

它包含用于放置各种用户难以处理的组件和图形的类。 但是,此类的组件取决于平台。 它们很重,并且依靠OS来运行。

The AWT package has classes using which we can create TextBoxes, CheckBoxes, RadioButton, List, etc.

AWT包具有一些类,通过这些类可以创建TextBoxesCheckBoxesRadioButtonList等。

层次结构 (Hierarchy)

Java AWT Introduction

Object: All classes in Java are inherited from the object class.

对象: Java中的所有类均从对象类继承。

Components: Elements like buttons, TextBox, RadioButton, etc. are called components in Java. We have separate classes for all components. To display elements on the screen, we need to place them in containers.

组件:按钮,文本框,单选按钮等元素在Java中称为组件。 对于所有组件,我们都有单独的类。 要在屏幕上显示元素,我们需要将其放置在容器中。

Container: It consists of classes that are used to hold other objects. All components are placed in containers, like Windows and Panels. Containers control the placement and layout of the components placed in them. A container in itself is a component.

容器:由用于容纳其他对象的类组成。 所有组件都放置在容器中,例如Windows和Panels。 容器控制放置在其中的组件的放置和布局。 容器本身就是一个组件。

Label: As the name suggests, it is used as a label, or a method to display text on the screen. The user cannot change the content of a label. It represents a read-only text.

标签:顾名思义,它用作标签或在屏幕上显示文本的方法。 用户无法更改标签的内容。 它代表一个只读文本。

Read: Java AWT Label

阅读: Java AWT标签

Button: A button is like a push button. It consists of a label (name of the button) and generates an event when clicked.

按钮:按钮就像一个按钮。 它由一个标签(按钮的名称)组成,并在单击时生成一个事件。

Read: Java AWT Button

阅读: Java AWT按钮

Checkbox: It is used to provide options. When clicked, it changes the state of the checkbox from 'on' to 'off' or vice-versa.

复选框:用于提供选项。 单击时,它将复选框的状态从“打开”更改为“关闭”,反之亦然。

Read: Java AWT Checkbox

阅读: Java AWT复选框

TextField: It is used to take single-line text input from the user. It can also be used to display editable text. Unlike a label, which provides read-only text, the text in the textfield can be edited by the user.

TextField:用于接受用户的单行文本输入。 它也可以用来显示可编辑的文本。 与提供只读文本的标签不同,文本字段中的文本可由用户编辑。

Read: Java AWT TextField

阅读: Java AWT TextField

TextArea: It allows the display of multiple lines of text. It provides 'an area' where text can be displayed and also edited by the user.

TextArea:它允许显示多行文本。 它提供了一个“区域”,用户可以在其中显示和编辑文本。

Read: Java AWT TextArea

阅读: Java AWT TextArea

一个简单的Java AWT程序 (A Simple Java AWT program)

import java.awt.*;

public class HelloWorld{

     public static void main(String []args){
        Frame f = new Frame();
        Button b1 = new Button("Click me!");
        Label l1 = new Label("Label");
        TextField t1 = new TextField("Text");
        b1.setBounds(50,50,100,50);
        l1.setBounds(50,100,100,50);
        t1.setBounds(50,150,100,50);
        
        f.setLayout(null);
        f.setSize(300,300);
        f.setVisible(true);
        
        f.add(b1);
        f.add(l1);
        f.add(t1);
        
     }
}

Output

输出量

Java AWT Introduction program

In this example, we create a button with the title "Click me", a label with un-editable text "Label" and a TextField with editable text. The text of the Textfield has been changed by the user from "Text" to "Changed user".

在此示例中,我们创建一个标题为“ Click me”的按钮,一个具有不可编辑文本“ Label”的标签和一个具有可编辑文本的TextField。 用户已将Textfield的文本从“ Text ”更改“ Changed user”

All these components are placed on a frame (a container), using the add() function. The position and size of these elements are decided by the setBounds() function. The size of the frame is set by the setSize() function and the frame, including all components, is made visible by the setVisible() function.

使用add()函数所有这些组件放置在框架(容器)上。 这些元素的位置和大小由setBounds()函数确定。 框架的大小由setSize()函数设置,并且框架(包括所有组件)通过setVisible()函数可见。

翻译自: https://www.includehelp.com/java/awt-introduction.aspx

java awt

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值