Write a Java program that behaves as follows: The user is shown a menu (or serie
ID: 3575873 • Letter: W
Question
Write a Java program that behaves as follows:
The user is shown a menu (or series of menus) in the console window to choose out of four figures to be drawn or painted (choose four from the list - line, rectangle, filled rectangle, 3D rectangle, filled 3D rectangle, round rectangle, filled round rectangle, oval, filled oval, arc, or filled arc).
After the user chooses the figure, he/she is prompted to enter the values for the parameters, associated with this figure in the console window.
The requested figure is drawn on a JFrame object and a message dialog box displays the name of the figure (e.g. "filled 3D rectangle")
Challenge: Draw the chosen figure 10 times with gradually changed location and size.
If the drawing does not appear on the screen, before drawing include next delay statement:
try { Thread.sleep(200) ; }catch(Exception e) {}
introduces delay of 200 ms. If you still may not see the drawing, increase the delay (e.g. 2000).
Explanation / Answer
Ask User 4 choices and make 10 different functions for all the 10 shapes. Call required 4 functions while printing the shape 10 times, with autoincrement or autodecrement of size and distance.
EX , FOR 3d RECTANGLE, use the below code
public class Rectangle3D {
protected Rect3D originPoint;
protected Rect3D xPoint;
protected Rect3D yPoint;
protected Rect3D zPoint;
public Rectangle3D() {
}
public Rectangle3D(Rect3D originPoint, Rect3D xPoint,
Rect3D yPoint, Rect3D zPoint) {
this.originPoint = originPoint;
this.xPoint = xPoint;
this.yPoint = yPoint;
this.zPoint = zPoint;
}
public void setOriginPoint(Rect3D originPoint) {
this.originPoint = originPoint;
}
public void setxPoint(Rect3D xPoint) {
this.xPoint = xPoint;
}
public void setyPoint(Rect3D yPoint) {
this.yPoint = yPoint;
}
public void setzPoint(Rect3D zPoint) {
this.zPoint = zPoint;
}
public void render(Graphics g, Rect3D viewPoint) {
}
public class Rect3D {
protected int x;
protected int y;
protected int z;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.