SlideShare a Scribd company logo
1 of 5
Download to read offline
Write a Java program that creates a drawing area of appropriate size (try 500 x 500) and draws a
house similar to the one shown below and adding a button to make the house turn on the light,
and anthor button to make the house turn off the light. When turn on the light the windows
should become yellow color.
1.The house should fill up most of the drawing area, i.e. draw it big.
2.The house should be centered horizontally on the screen.
3.The house must have a sloped roof. It can be of any slope or configuration. But you cannot
have a flat roof on the house.
4.Adding a door (centered) and windows
5.Adding a button to make the house turn on the light, and anthor button to make the house turn
off the light. When turn on the light the windows should become yellow color. DrawingTool File
Speed
Solution
These classes are not part of Java but are available through the library named apcslib. You must
have
the file apcslib.jar in the appropriate directory where Java can access it. To have these classes
available in your program, use this command:
import apcslib.*;
Other features of apcslib will be covered in later lessons.
DrawingTool
protected double
protected xPos
protected yPos
protected direction;
protected int width;
protected boolean isDown;
protected Color color;
...
<>
DrawingTool()
DrawingTool(SketchPad)
...
<>
public Color getColor()
public double getDirection()
public Point2D.Double getPosition()
public int getWidth()
public String toString()
<>
public void backward(double)
public void down()
public void drawString(String)
public void drawCircle(double)
public void forward(double)
public void home()
public void move(double)
public void move(double, double)
public void setColor(Color)
public void setDirection(double)
public void setWidth(int)
public String toString()
public void turn (double)
public void turnLeft(double)
public void turnRight(double)
DRAWINGTOOL CLASS SPECIFICATIONS
public void up()
...
Invariant
A DrawingTool object
· Appears in a SketchPad Window (this window is 500 pixels wide and 500 pixels high initially,
but
can be constructed with different dimensions.)
· The origin (0, 0) is at the center of the drawing window.
· Is directed either up, down, left, or right.
· Is either in drawing mode or in moving mode.
Constructor Methods
public DrawingTool()
postcondition
· A new DrawingTool is created and placed in the center (0, 0) of a SketchPad window that
is 500 pixels wide and 500 pixels high.
· This object is set to drawing mode.
· The direction for this object is up (90º).
· The DrawingTool color is set to blue.
· The DrawingTool width is 1.
public DrawingTool(SketchPad win)
postcondition
· A new DrawingTool is created and placed in the center (0, 0) of the SketchPad window
win.
· This object is set to drawing mode.
· The direction for this object is up (90º).
· The DrawingTool color is set to blue.
· The DrawingTool width is 1.
Accessor Methods
public String toString();
postcondition
result = color
public Color getColor();
postcondition
result = color
public double getDirection();
postcondition
result = direction
public int getWidth();
DRAWINGTOOL CLASS SPECIFICATIONS
postcondition
result = width
Modifier Methods
public backward (double distance);
postcondition
· This DrawingTool object is moved backward from current direction by distance pixels
from the old (previous) location.
· If this object is in drawing mode, a line segment is drawn across the distance path just
traversed.
· The direction is unchanged.
· A 0.5 second delay occurs following this method’s execution.
public void down();
postcondition
· This object is set to drawing mode.
public drawString(String text);
postcondition
· The string text is drawn at the current location using the current color.
public drawCircle (double r);
postcondition
· If the object is in drawing mode, a circle of radius r is drawn around the current location using
the
current width and color.
public forward(double distance);
postcondition
· This DrawingTool object is moved in the current direction by distance pixels from the old
(previous) location.
· If this object is in drawing mode, a line segment is drawn across the distance path just
traversed.
· A 0.5 second delay occurs following this method’s execution.
public home();
postcondition
· The location of the DrawingTool object is set to the center of the SketchPad window.
· The drawing direction of the object is ups.
public move(double d);
postcondition
· This DrawingTool object is moved in the current direction by d pixels from the old (previous)
location.
· If this object is in drawing mode, a line segment is drawn across the d path just traversed.
public move(double x, double y);
postcondition
DRAWINGTOOL CLASS SPECIFICATIONS
· This DrawingTool object is moved from the current position to the position specified by the
coordinates x and y.
· If this object is in drawing mode, a line segment is drawn from the old (previous) position to
the
absolute position specified by x and y.
public setColor(Color c);
precondition
· c is a valid Color
postcondition
· The color of the DrawingTool object is set to c.
public setDirection(double d);
postcondition
· Sets the direction to d degrees. The orientation is d degrees counterclockwise from the positive
xaxis
public setWidth(int w);
precondition
· w is >= 1
postcondition
· The width of the DrawingTool object is set to w pixels.
public turn(double d);
postcondition
· Changes the current direction counterclockwise by d degrees from the current direction.
public turnLeft(double degrees);
postcondition
· Changes the current direction counterclockwise by d degrees from the current direction.
public turnRight(double degrees);
postcondition
· Changes the current direction clockwise by d degrees from the current direction.
public up();
postcondition
· This object is set to moving mode.

More Related Content

Similar to Write a Java program that creates a drawing area of appropriate size.pdf

Unity - Create a structure with primitives
Unity - Create a structure with primitivesUnity - Create a structure with primitives
Unity - Create a structure with primitivesNexusEdgesupport
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene GraphsSyed Zaid Irshad
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Polybot Onboarding Process
Polybot Onboarding ProcessPolybot Onboarding Process
Polybot Onboarding ProcessNina Park
 
XNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and AnimationXNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and AnimationMohammad Shaker
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfSALES97
 
The Noland national flag is a square showing the following pattern. .docx
 The Noland national flag is a square showing the following pattern.  .docx The Noland national flag is a square showing the following pattern.  .docx
The Noland national flag is a square showing the following pattern. .docxKomlin1
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Honeymoon suite bedroom tutorial ferry
Honeymoon suite bedroom tutorial ferryHoneymoon suite bedroom tutorial ferry
Honeymoon suite bedroom tutorial ferryNomer Adona
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive ProgramsSyed Zaid Irshad
 

Similar to Write a Java program that creates a drawing area of appropriate size.pdf (20)

Unity - Create a structure with primitives
Unity - Create a structure with primitivesUnity - Create a structure with primitives
Unity - Create a structure with primitives
 
Graphical Objects and Scene Graphs
Graphical Objects and Scene GraphsGraphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Polybot Onboarding Process
Polybot Onboarding ProcessPolybot Onboarding Process
Polybot Onboarding Process
 
XNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and AnimationXNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and Animation
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdf
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
The Noland national flag is a square showing the following pattern. .docx
 The Noland national flag is a square showing the following pattern.  .docx The Noland national flag is a square showing the following pattern.  .docx
The Noland national flag is a square showing the following pattern. .docx
 
mastercam_full
mastercam_fullmastercam_full
mastercam_full
 
mastercam_full
mastercam_fullmastercam_full
mastercam_full
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Honeymoon suite bedroom tutorial ferry
Honeymoon suite bedroom tutorial ferryHoneymoon suite bedroom tutorial ferry
Honeymoon suite bedroom tutorial ferry
 
P5js syracuse dev meetup 20181218
P5js syracuse dev meetup 20181218P5js syracuse dev meetup 20181218
P5js syracuse dev meetup 20181218
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive Programs
 
Chapter 8
Chapter 8Chapter 8
Chapter 8
 

More from boothlynntur11512

Lean methodology as it is practiced today can be traced back to Mot.pdf
Lean methodology as it is practiced today can be traced back to  Mot.pdfLean methodology as it is practiced today can be traced back to  Mot.pdf
Lean methodology as it is practiced today can be traced back to Mot.pdfboothlynntur11512
 
is about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfis about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfboothlynntur11512
 
In C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfIn C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfboothlynntur11512
 
How important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfHow important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfboothlynntur11512
 
give me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfgive me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfboothlynntur11512
 
explain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfexplain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfboothlynntur11512
 
Discuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfDiscuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfboothlynntur11512
 
Define the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfDefine the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfboothlynntur11512
 
Describe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfDescribe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfboothlynntur11512
 
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfCousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfboothlynntur11512
 
Create two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfCreate two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfboothlynntur11512
 
Chrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfChrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfboothlynntur11512
 
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfChapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfboothlynntur11512
 
×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdfboothlynntur11512
 
You are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfYou are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfboothlynntur11512
 
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfWhy is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfboothlynntur11512
 
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfWhich of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfboothlynntur11512
 
Which of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfWhich of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfboothlynntur11512
 
What is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfWhat is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfboothlynntur11512
 
This is Java programing. Modify the balls.java program so that all t.pdf
This is Java programing. Modify the balls.java program so that all t.pdfThis is Java programing. Modify the balls.java program so that all t.pdf
This is Java programing. Modify the balls.java program so that all t.pdfboothlynntur11512
 

More from boothlynntur11512 (20)

Lean methodology as it is practiced today can be traced back to Mot.pdf
Lean methodology as it is practiced today can be traced back to  Mot.pdfLean methodology as it is practiced today can be traced back to  Mot.pdf
Lean methodology as it is practiced today can be traced back to Mot.pdf
 
is about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfis about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdf
 
In C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfIn C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdf
 
How important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfHow important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdf
 
give me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfgive me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdf
 
explain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfexplain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdf
 
Discuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfDiscuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdf
 
Define the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfDefine the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdf
 
Describe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfDescribe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdf
 
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfCousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
 
Create two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfCreate two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdf
 
Chrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfChrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdf
 
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfChapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
 
×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf
 
You are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfYou are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdf
 
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfWhy is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
 
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfWhich of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
 
Which of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfWhich of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdf
 
What is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfWhat is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdf
 
This is Java programing. Modify the balls.java program so that all t.pdf
This is Java programing. Modify the balls.java program so that all t.pdfThis is Java programing. Modify the balls.java program so that all t.pdf
This is Java programing. Modify the balls.java program so that all t.pdf
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Write a Java program that creates a drawing area of appropriate size.pdf

  • 1. Write a Java program that creates a drawing area of appropriate size (try 500 x 500) and draws a house similar to the one shown below and adding a button to make the house turn on the light, and anthor button to make the house turn off the light. When turn on the light the windows should become yellow color. 1.The house should fill up most of the drawing area, i.e. draw it big. 2.The house should be centered horizontally on the screen. 3.The house must have a sloped roof. It can be of any slope or configuration. But you cannot have a flat roof on the house. 4.Adding a door (centered) and windows 5.Adding a button to make the house turn on the light, and anthor button to make the house turn off the light. When turn on the light the windows should become yellow color. DrawingTool File Speed Solution These classes are not part of Java but are available through the library named apcslib. You must have the file apcslib.jar in the appropriate directory where Java can access it. To have these classes available in your program, use this command: import apcslib.*; Other features of apcslib will be covered in later lessons. DrawingTool protected double protected xPos protected yPos protected direction; protected int width; protected boolean isDown; protected Color color; ... <> DrawingTool() DrawingTool(SketchPad) ... <>
  • 2. public Color getColor() public double getDirection() public Point2D.Double getPosition() public int getWidth() public String toString() <> public void backward(double) public void down() public void drawString(String) public void drawCircle(double) public void forward(double) public void home() public void move(double) public void move(double, double) public void setColor(Color) public void setDirection(double) public void setWidth(int) public String toString() public void turn (double) public void turnLeft(double) public void turnRight(double) DRAWINGTOOL CLASS SPECIFICATIONS public void up() ... Invariant A DrawingTool object · Appears in a SketchPad Window (this window is 500 pixels wide and 500 pixels high initially, but can be constructed with different dimensions.) · The origin (0, 0) is at the center of the drawing window. · Is directed either up, down, left, or right. · Is either in drawing mode or in moving mode. Constructor Methods public DrawingTool() postcondition · A new DrawingTool is created and placed in the center (0, 0) of a SketchPad window that
  • 3. is 500 pixels wide and 500 pixels high. · This object is set to drawing mode. · The direction for this object is up (90º). · The DrawingTool color is set to blue. · The DrawingTool width is 1. public DrawingTool(SketchPad win) postcondition · A new DrawingTool is created and placed in the center (0, 0) of the SketchPad window win. · This object is set to drawing mode. · The direction for this object is up (90º). · The DrawingTool color is set to blue. · The DrawingTool width is 1. Accessor Methods public String toString(); postcondition result = color public Color getColor(); postcondition result = color public double getDirection(); postcondition result = direction public int getWidth(); DRAWINGTOOL CLASS SPECIFICATIONS postcondition result = width Modifier Methods public backward (double distance); postcondition · This DrawingTool object is moved backward from current direction by distance pixels from the old (previous) location. · If this object is in drawing mode, a line segment is drawn across the distance path just traversed. · The direction is unchanged. · A 0.5 second delay occurs following this method’s execution.
  • 4. public void down(); postcondition · This object is set to drawing mode. public drawString(String text); postcondition · The string text is drawn at the current location using the current color. public drawCircle (double r); postcondition · If the object is in drawing mode, a circle of radius r is drawn around the current location using the current width and color. public forward(double distance); postcondition · This DrawingTool object is moved in the current direction by distance pixels from the old (previous) location. · If this object is in drawing mode, a line segment is drawn across the distance path just traversed. · A 0.5 second delay occurs following this method’s execution. public home(); postcondition · The location of the DrawingTool object is set to the center of the SketchPad window. · The drawing direction of the object is ups. public move(double d); postcondition · This DrawingTool object is moved in the current direction by d pixels from the old (previous) location. · If this object is in drawing mode, a line segment is drawn across the d path just traversed. public move(double x, double y); postcondition DRAWINGTOOL CLASS SPECIFICATIONS · This DrawingTool object is moved from the current position to the position specified by the coordinates x and y. · If this object is in drawing mode, a line segment is drawn from the old (previous) position to the absolute position specified by x and y. public setColor(Color c);
  • 5. precondition · c is a valid Color postcondition · The color of the DrawingTool object is set to c. public setDirection(double d); postcondition · Sets the direction to d degrees. The orientation is d degrees counterclockwise from the positive xaxis public setWidth(int w); precondition · w is >= 1 postcondition · The width of the DrawingTool object is set to w pixels. public turn(double d); postcondition · Changes the current direction counterclockwise by d degrees from the current direction. public turnLeft(double degrees); postcondition · Changes the current direction counterclockwise by d degrees from the current direction. public turnRight(double degrees); postcondition · Changes the current direction clockwise by d degrees from the current direction. public up(); postcondition · This object is set to moving mode.