AWTに関する世界観です。Javaの世界観(A.GUI)も参照のこと。
AWTはJavaのGUIツールキットで、Swingほど高度ではないものの軽量なGUI開発が可能。
以下はAWTを使ったアプレットのサンプル。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="hoge.class" width="250" height="60">
</applet>
*/
public class Hoge extends Applet implements ActionListener {
Label hogeLabel;
Button hogeButton;
public void init() {
hogeLabel = new Label("My name is Hoge.");
add(hogeLabel);
hogeButton = new Button("Say hello");
hogeButton.addActionListener(this);
add(hogeButton);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == hogeButton) {
hogeLabel.setText("Hello, I'm Hoge!");
}
}
}
(新Java言語入門 ビギナー編を参考に執筆しました。)
2026.01.07
Swingを参照のこと。