created 01/08/02

Chapter 57 Programming Exercises

Exercise 1 — Toggle Color Button

Modify the ButtonDemo program so that it changes the color of the frame for every click of the button. Change the color back and forth from red and blue. Start the frame out with a blue background.

Click here to go back to the main menu.

Click here view the solution for this question.


Exercise 2 — Click Counter

Modify the ButtonDemo program so that the text on the button shows how many times the button has been clicked. Use the JButton method setText(String text) to change the button's text.

Click here to go back to the main menu.

Click here view the solution for this question.


Exercise 3 — Improved Click Counter

Modify the ButtonDemo program so the frame includes both a button and a label. The label starts out displaying the string "0" and for each click of the button changes to display the number of times the button has been clicked. Use the JLabel method setText(String text).

Click here to go back to the main menu.

Click here view the solution for this question.