Posts

Showing posts from November, 2019

How to display different shapes using GUI? Solution:

Problem Description: How to display different shapes using GUI? Solution: Following example demonstrates how to display different shapes using Arc2D, Ellipse2D, Rectangle2D, RoundRectangle2D classes. import java.awt.Shape; import java.awt.geom.*; publicclassMain{ publicstaticvoid main(String[] args){ int x1=1, x2=2, w=3, h=4, x=5, y=6, y1=1, y2=2, start=3; Shape line=newLine2D.Float(x1, y1, x2, y2); Shape arc=newArc2D.Float(x, y, w, h, start,1,1); Shape oval=newEllipse2D.Float(x, y, w, h); Shape rectangle=newRectangle2D.Float(x, y, w, h); Shape roundRectangle=newRoundRectangle2D.Float (x, y, w, h,1,2); System.out.println("Different shapes are created:"); } }Result: The above code sample will produce the following result. Different shapes are created. 2. Write a value-returning method namedreverseDigit, that takes an int (integer) as a parameter and returns the number with its digits reversed as an int. For example, callingreverseDigit(12345) returns the int value of