A door with a handle.,A couple of windows with frames, A roof ,A chimney, A lawn
ID: 3847435 • Letter: A
Question
A door with a handle.,A couple of windows with frames, A roof ,A chimney, A lawn
Using the sleep command, animate some small parts of the pictures. Options include:
Have the sun move across the screen.
add raindrops.
And moving animals to the front lawn.
Add a moving UFO.
Its up to you, have a little fun and enjoy this final assignment.
For full credit you should have at least one additional user created object that is part of your animation.
Explanation / Answer
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Graphics; public class DrawHouse extends JApplet implements MouseListener { private int mX; //variable to hold x position of the mouse cursor when clicked private int mY; //variable to hold y position of the mouse cursor when clicked private int rect1x; private int rect1y; private int rect1w; private int rect1h; private int rect2x; private int rect2y; private int rect2w; private int rect2h; private int rect3x; private int rect3y; private int rect3w; private int rect3h; boolean rect1Clicked; boolean rect2Clicked; boolean rect3Clicked; public void init() { super.init(); } public void paint(Graphics g) { super.paint(g); Polygon pg = new Polygon(); pg.addPoint(280, 200); pg.addPoint(470, 100); pg.addPoint(670, 200); g.drawPolygon(pg); g.setColor(Color.BLACK); g.drawRect(300, 200, 350, 300); g.fillRect(350, 300, 50, 100); g.fillRect(550, 300, 50, 100); g.fillRect(440, 300, 75, 200); addMouseListener(this); if(rect1Clicked || rect2Clicked || rect3Clicked) { g.setColor(Color.GRAY); g.clearRect(rect1x, rect1y, rect1w, rect1h); g.fillRect(rect1x, rect1y, rect1w, rect1h); g.setColor(Color.GRAY); g.clearRect(rect2x, rect2y, rect2w, rect2h); g.fillRect(rect2x, rect2y, rect2w, rect2h); g.setColor(Color.GRAY); g.clearRect(rect3x, rect3y, rect3w, rect3h); g.fillRect(rect3x, rect3y, rect3w, rect3h); } } @Override public void mouseClicked(MouseEvent e) { rect1x = 350; rect1y = 300; rect1w = 350; rect1h = 300; rect2x = 550; rect2y = 300; rect2w = 50; rect2h = 100; rect3x = 440; rect3y = 300; rect3w = 75; rect3h = 200; mX = e.getX(); mY = e.getY(); if(mX > rect1x && mX rect1y && mY rect2x && mX rect2y && mY rect3x && mX rect3y && mYRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.