Question: Using Java JCreator: Edit the code below to have the circles going through the rectangles within the drawing, the drawing must also be scaleable import
Using Java JCreator: Edit the code below to have the circles going through the rectangles within the drawing, the drawing must also be scaleable
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class ShapesTest {
public static void main(String[] a) {
String input=JOptionPane.showInputDialog("Enter 1 to draw rectangles " +"Enter 2 to draw ovals");
int choice=Integer.parseInt(input);
Shapes panel=new Shapes(choice);
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(300, 300);
application.setVisible(true);
}
}
class Shapes extends JComponent {
int input;
Shapes(int input)
{
this.input=input;
}
public void paint(Graphics g)
{
int x=20,y=20,w=20,z=20;
if(input==1)
{
for(int i=1;i<=10;i++) ////used to draw rectangles
{ x=x+10;
y=y+10;
w=w+10;
z=z+10;
g.drawRect (x, y, w, z);
}
}else if(input==2)
{
for(int i=1;i<=10;i++) ////used to draw circles
{ x=x+10;
y=y+10;
w=w+10;
z=z+10;
g.drawOval (x, y, w, z);
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
