Big Java Late Objects
Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 24, Problem 6PP
Program Plan Intro

Draw Rectangle

Program plan:

Filename: “rectangle.java”

This program file is used to define a component “rectangle”.

  • Define a component “x”.
  • Define a component “y”.
  • Define a component “width”.
  • Define a component “height”.

Filename: “RectangleParser.java”

This program file is used to define a class “RectangleParser”. In the code,

  • Import the required packages.
  • Define a class “RectangleParser”.
    • Declare the class members “builder” and “path”.
    • Define the constructor “RectangleParser()”.
      • Define the object of “DocumentBuilderFactory”.
      • Initialize “builder”.
      • Initialize “path”.
    • Define a method “parse()”.
      • Define the object of “File” named “f”.
      • define an object “doc”.
      • Get the rectangle element “x”.
      • Get the rectangle element “y”.
      • Get the rectangle element “width”.
      • Get the rectangle element “height”.
      • Define the object “rectangle” of “Rectangle”.’
      • Return the object “rectangle”.

Filename: “RectangleComponent.java”

This program file is used to define a class “RectangleComponent”. In the code,

  • Define a class “RectangleComponent”.
    • Declare the class member “box”.
    • Define the constructor “RectangleComponent()”.
      • Initialize “box”.
    • Define a method “paintComponent()”,
      • Define the object of “Graphics2D” named “g2”.
      • Call “draw()”.

Filename: “JFrame.java”

This program file is used to define a class “JFrame”. In the code,

  • Import the required packages.
  • Define a class “JFrame”.
    • Declare the class members “size”, “components” and “EXIT_ON_CLOSE”.
    • Define the method “setSize()”.
      • Set “size”.
    • Define a method “setDefaultCloseOperation()”,
    • Define a method “add()”,
      • Call the method “add()” to add “c”.
    • Define a method “setVisible()”,
      • Define a string “fileName”.
      • Define the object of “Rectangle”.
      • Define the object of “BufferedImage”.
      • Define the object of “Graphics2D”.
      • Call the method “setColor()”.
      • Call the method “fill()”.
      • Call the method “setColor()”.
      • Define “try” block.
      • Define “catch” block.
      • Call “dispose()”.

Filename: “RectangleViewer.java”

This program file is used to define a class “RectangleViewer”. In the code,

  • Import the required packages.
  • Define a class “RectangleViewer”.
    • Define the method “main()”.
      • Define the object “rp” of class “RectangleParser”.
      • Define the object “r” of class “Rectangle”.
      • Define the object “rectComponent” of class “RectangleComponent”.
      • Define the object “frame” of class “JFrame”.
      • Call “setDefaultCloseOperation()”.
      • Call the method “add()”.
      • Call the method “setSize()”.
      • Call the method “setVisible()”.

Blurred answer
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education