Question: Following Java program should draw a square in the middle of the existing frame, and a circle inside the square. Complete the code using the
Following Java program should draw a square in the middle of the existing frame, and a circle inside the square. Complete the code using the provided comments. Note that the drawing components should be always in the middle of the frame when you resize your window. // import JFrame and JComponent classes
import _________________________
import _________________________
import java.awt.*;
/* Drawing component class. */
public class DrawingViewer {
public static void main(String[] args) {
JFrame frame = new JFrame()
; // Set the size of the frame, width 400 and height 300
frame.____________________;
frame.setTitle("Shapes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create an object of the DrawingComponents class and
// add it to the frame
__________________________________________________
__________________________________________________
// make the frame visible
_________________________
}
}
/* Viewer class. */
class DrawingComponents extends JComponent {
public void paintComponent(Graphics g) {
// Cast g to a Graphics2D object g2.
_________________________
// Construct the square and draw it. Width of the square is 100.
__________________________________________________
__________________________________________________
// Construct the circle and draw it. Circle diameter is 60.
Ellipse2D.Double circle = new Ellipse2D.Double(_______________________);
// Construct a rectangle and draw it
__________________________________________________
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
