• Home
  • Blog
  • Write the Java code for each of the exercises in the attached document. Compile, debug and test via BlueJ.

Write the Java code for each of the exercises in the attached document. Compile, debug and test via BlueJ.

0 comments

studyWeek 2 Lab

Exercise 1

Write a simple program called TurnBlue that does the following:

When the program begins a red square is drawn. Each side of the square is 60 pixels, and the square is located 70 pixels from the right and 60 pixels down from the top left corner.

• When the mouse is clicked, the square turns blue.

• When the mouse exits the window the square disappears.

• When the mouse re-enters the window the square reappears and is once again red.

Exercise 2

Write a program called Scribble. On mousePress, save the starting location. On mouseDrag, draw a line that follows the mouse. Should allow you to scribble on the canvas.

Exercise 3

Write a simple program called Measles with these features:

• When the program begins there should be a message telling the user “Measles: Click to catch the disease!”

• When the user clicks the mouse a red dot should form at the location where the mouse was clicked. Make the diameter of the dots 5 pixels. The introductory message should no longer be visible.

• When the mouse exits the window the user should be cured. Thus all the spots should disappear and a message saying “You have been cured!” should appear.

• When the mouse re-enters the window the original message should reappear.

Perform the following tasks:

  • Write the Java code for each of the exercises in the attached document.
  • Compile, debug and test via BlueJ.
  • Save the .java code for each exercise
  • Submit here

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}