Repeat after Me

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.
go to previous page   go to home page   go to next page

Answer:

An object which implements ActionListener.

Repeat after Me

Here an application that has two JTextFields. The user types into one field and hits enter. The application then copies text from that field to the other.

GUI of the application

In the picture, the user typed in "Sherlock" and then hit enter. Here is an applet that does much the same thing. Swing components work in applets as well as applications.

Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.

Type your name in the first box and see it echoed to the second. The code for the applet is nearly the same as the code for the application.

QUESTION 9:

  • How many components does the frame contain?
  • Which of them needs a listener?