Design and code a program, including the following classes, as well as a client
ID: 3801276 • Letter: D
Question
Design and code a program, including the following classes, as well as a client applet class to test all the methods coded: An abstract Shape class, encapsulating a shape: a shape has one abstract method, draw, which takes one parameter, a Graphics object. Shape has three subclasses: The Line class, encapsulating a line: A line can be represented by a starting (x, y) coordinate and an ending (x, y) coordinate. The draw method will draw a line between them. The Rectangle class, encapsulating a rectangle: A rectangle can be represented by its (x, y) top-left corner of the rectangle, its width, and its height. The draw method will draw the corresponding rectangle. The Oval class, encapsulating an oval: An oval can be represented by the (x, y) top-left corner coordinate of its bounding rectangle, its width, and its height. The draw method will draw the corresponding oval. Your applet class should prompt the user for the type of shape that the user wants to draw, prompt the user for the appropriate data, and then draw the figure in the applet window.Explanation / Answer
public class Appletshapes extends Applet {
private int option;
public void init() {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
public void paint(Graphics g){
if (e.getKeyCode()) {
switch (shape) {
case 1:
g.drawLine(250,250,100,100);
case 2:
g.drawRect(250,250,100,100);
case 3:
g.drawOval(250,250,100,100);
case 4:
break;
}
}
}
});
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.