New Program

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.
go to previous page   go to home page   go to next page

Answer:

Yes. Our new program will do this.

New Program

Click here to exit

Let us write a new program:

  • The frame contains a button.
    • The frame will be the listener for the button.
    • The frame will implement ActionListener.
    • It will have an actionPerformed() method.
  • Clicking on the button will exit the program.
    • The actionPerformed() method calls System.exit(0).
  • The class of the frame contains the static main() method.

Often a real application has several ways to quit: the window's close button, a menu selection, and perhaps a button like this program.

QUESTION 19:

What Swing classes will be used in the program?