Java Practice Exercise – Event Handling and Swing Components

  • Create a calculator using swing components
  • Write a Java program to toggle the background color on every click of button
  • Create a new Java GUI application to convert miles to kilometers when pressing the “Convert!” button. Note that you need to implement the ActionListener interface and override the actionPerformed() method. Note that 1 mile is equal to 1.609 kilometers.
  • Write a java program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green with radio buttons. On selecting a button, an appropriate message with stop or ready or go should appear above the buttons in a selected color. Initially there is no message shown.
  • Create a new Java GUI application that moves a snowman on a panel. The position of the snowman can be changed using the control buttons. With the four buttons, a user can move the snowman to the left, right, up or down position