
To draw the red square and fill it with the specified background of yellow color it is need to use three methods such as “Rectangle()”, “fill()”, and “SetColor()”.
Rectangle() method:
- For two dimensional objects, the graphics2D class is used to draw the objects.
- The “Rectangle()” method contains the respective four co-ordinates such as “left, “top” , “right”, and “bottom”.
- The first parameter “left” represents the x-coordinate of top left corner.
- The second parameter “top” represents the y-coordinate of top left corner.
- The third parameter “right” represents the x-coordinate of right bottom corner.
- The fourth parameter “bottom” represents the y-coordinate of right bottom corner.
- The “Rectangle()” method follows the same co-ordinates of rectangle object. But for right and bottom co-ordinate it passes the same value as an argument to draw the square.
Let use the following syntax to draw the rectangle or square,
Rectangle(left,top,right,bottom);
Fill and set the color using “fill()”and “setColor()”:
Normally, the text strings and shapes drawn on the window are drawn with black color pen. To change the color of the string, the java uses the object type of “Color.Java” to set the Red, Green, and Blue (RGB) values.
Let use the following syntax to set the color,
// Set the color passed as argument
g2.setColor(Color.nameofcolor);
The method “setColor()” is used to set the specified color.
Let use the following syntax to fill the shape of the color,
// Fill the color inside of the shape
g2.fill(shape);
The method “fill()” is used to fill the color for specified shape passed as argument.

Want to see the full answer?
Check out a sample textbook solution
Chapter 2 Solutions
EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
- Ninth Edition Determine Zi, Zo and Av 20 V Zi + 1 ΜΩ 2 ΚΩ HH Z IDSS= 6MA Vp=-6V Yos = 40μS 20 and 47arrow_forwardWhat is the worst case time complexity of the following algorithm for i = 1 to x do for j = 2^((i-1)x) to 2^(in) do print(i,j)arrow_forwardProve for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forward
- I need to make a parallel version of this sequential codearrow_forwardI need to make a parallel version of this sequential code.arrow_forwardBenefits of using arrays as instance variables: What are the advantages of incorporating arrays as instance variables within a class? Initializing and managing arrays: How do you initialize and manage arrays within class constructors and mutators (setters)? Example of using arrays as instance variables: Share an example where you have used arrays as instance variables and discuss its application in a real-world scenario. Common mistakes with arrays as instance variables: What are some common mistakes to avoid when working with arrays as instance variables? Information hiding violations: What is the potential violation of information hiding when using arrays as instance variables? How can this be resolved?arrow_forward
- Do you think that computers should replace teachers? Give three references with your answer.arrow_forwardIs online learning or face to face learning better to teach students around the around the world? Give reasons for your answer and provide two references with your response. What are benefits of both online learning and face to face learning ? Give two references with your answer. How does online learning and face to face learning affects students around the world? Give two references with your answer.arrow_forwardExplain Five reasons if computers should replace teachers. Provide three references with your answer. List three advantages and three disadvantages face to face learning and online learning may have on children. Provide two references with your answer.arrow_forward
- You were requested to design IP addresses for the following network using the address block 10.10.10.0/24. Specify an address and net mask for each network and router interfacearrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forwardFor the following network, propose routing tables in each of the routers R1 to R5arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





