Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class AppletDemo in next slide misses some parts of code including import statem

ID: 3542093 • Letter: C

Question


Class AppletDemo in next slide misses some parts of code including import statement and variable initialization. So if you compile and run it in the current format, it will generate errors. Correct the code (do not replace the variables with values; make sure you initialize them in the program), compile and run it.


public class AppletDemo extends JApplet {

public void paint(Graphics g)

{

super.paint(g);

resize(xResize,yResize);

g.setColor(Color.YELLOW);

g.drawOval(xOval,yOval,widthOval,heightOval);

g.setColor(Color.BLUE);

g.fillRect(xRect,yRect,widthRect,heightRect);

g.setColor(Color.RED);

Polygon triangle = new Polygon ();

triangle.addPoint(x1,y1);

triangle.addPoint(x2,y2);

triangle.addPoint(x3,y3);

g.fillPolygon(triangle);

}

Explanation / Answer

Try this :


import java.awt.Color;

import java.awt.Graphics;

import java.awt.Polygon;


import javax.swing.JApplet;


public class AppletDemo extends JApplet {

public void paint(Graphics g)

{

super.paint(g);

resize(400,400);

g.setColor(Color.YELLOW);

g.drawOval(10,10,50,50);

g.setColor(Color.BLUE);

g.fillRect(70,10,100,100);

g.setColor(Color.RED);

Polygon triangle = new Polygon ();

triangle.addPoint(90,300);

triangle.addPoint(100,50);

triangle.addPoint(150,90);

g.fillPolygon(triangle);

}

}