Welcome to Computer Programming

 

HWJ8 - Mouse Input

 

Create these programs (start with the Gui_Builder and drag mouse in above for each example):

If working alone - do 4. If working with a partner 5. If advanced - do atleast 1 more than required.

  1. Create FindLocation that will display the location of where the mouse clicks and it will display that in 2 textfields (one for x, one for y)

  2. Create SquareDraw with a textfield that will allow the user to put in a size of a square. When the user clicks, it will draw that size square centered around the cursor. (int size=fieldName.getInt()

  3. Create LineDraw where a line will be drawn between where the user presses the button down to where they release the button. (g.drawLine(x,y,x2,y2))

  4. Create TopHalf that will change the applet to green if the mouse clicks on the top half and black if they click the bottom half. Use g.setColor and then g.fillRect to do that (or setBackground(Color.black) ).

  5. Create RectangleDraw where an rectangle will be drawn between where the user presses the button down to where they release the button. (Advanced people - make it work from any direction)

  6. Create RectClicked that in the paint method add this rectangle g.fillRect(200,200,100,100) - SEE BELOW - that will draw a rectangle in the middle of the screen. Then count the number of times the user clicks in the region and display this in a textfield

  7. Create DottedLine that when the user clicks it will draw a dotted lines from the center to where the user clicked. Advanced - display the distance of the line in the textfield, you will need the distance formula

Super advanced: Bring in timer and make a game out of it. (Like have an object appear and the user has to click it - keep tracker)