Event-driven Programming

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:

Click!

Event-driven Programming

When you perform an action on a graphical component you generate an event. In event-driven programming the program responds to these events. The order of the events is determined by the user, not the program.

This is different from programs where user interaction is done through the console. In these programs, prompts are written to the console, and the user responds to the prompts. The order of the prompts is determined by the program.

For example, you can generate an event by clicking on this button:     Or you could click on this button:    Click on the buttons a few more times in any order. The program (your Web browser, in this case) is event-driven and responds to the events in whatever order you generate them.

If your browser is written in Java, then Swing components generate the events and Java methods respond to them. If your browser is written in C++, then it uses other components and methods, similar to Swing. (Most browsers are written in C++).

QUESTION 4:

How do you imagine that I wrote this Web page:

  • By writing thousands and thousands of lines of code from scratch that implement buttons and events, or
  • By quickly using a few ready-made button components.