Complete 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:

It would not be unusual to miss a blank or two.

Complete Program

For such a complicated relationship diagram, this is a short program.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 

public class ButtonQuitter extends JFrame implements ActionListener
{
  JButton bQuit = new JButton("Click here to Exit");   
  
  public ButtonQuitter(String title) 
  {
    super(title);
    setLayout( new FlowLayout() );
    bQuit.addActionListener( this );
    add( bQuit );
  }
  
  public void actionPerformed( ActionEvent evt)
  {
    System.exit( 0 );
  }   
  
  public static void main ( String[] args )
  {
    ButtonQuitter frame = new ButtonQuitter("Button Quitter");
   
    frame.setSize( 200, 100 );  
    frame.setVisible( true );        
  }
}

The program can be copied to a file, compiled and run in the usual way.

QUESTION 23:

How many times must you click the JButton for the program to exit?