Review the code for an applet that works like a form.
Java Applet Tutorial
Building simple user interfaces is easy with the Java AWT. Components like buttons and input fields are provided for you to use. If you want a very simple appearance, and are not concerned with the precise appearance of your applet, you can get what you need in just a few lines of code. Here is the code for a complete applet that displays a form used to collect a name:
Applet appearance (JFC versus JavaFX)
line 1-2
import the applet and AWT classes to use their short names
line 4
start of the applet definition
line 5
typically the user interface is built in init()
line 7
add a text label to the applet user interface
line 8
create an input field for text
line 9
add the input field to the applet user interface
line 10
create a button
line 11
add the button to the applet user interface
line 12
end of the init() override
line 13
end of the applet
To test this applet, you will need HTML.
Here is a page that will work:
<html>
<head>
<title>Form Tester</title>
<body bgcolor=white>
<h1>This applet behaves like an HTML form</h1>
<applet code="FormApplet.class" width=300 height=80>
</applet>
</body>
</html>
The following diagram demonstrates what it looks like when this applet is run.
Of course, this applet does not actually do anything with the information you add to the form, it just displays the input field and button.
In the next lesson, you will learn to design an applet that sends GET to a servlet