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

For this assignment you copy the source code for a Java applet into a Word docum

ID: 3556679 • Letter: F

Question

For this assignment you copy the source code for a Java applet into a Word document and then write your own comments for each line of code.

how do i do that?

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

// Applet that draws different colored circles.
public class ChoicesList extends Applet
{
private List choices;
private Graphics g;

public void init ()
{
choices = new List (3, false);
choices.add ("Red");
choices.add ("Yellow");
choices.add ("Green");
add (choices);
choices.addItemListener (new listListener ());
g = getGraphics ();
} // method init

class listListener implements ItemListener
{
public void itemStateChanged (ItemEvent event)
{
String choice = choices.getSelectedItem ();
int y = 0;
if (choice.equals ("Red"))
{
y = 50;
g.setColor (Color.red);
}
else if (choice.equals ("Yellow"))
{
y = 100;
g.setColor (Color.orange);
}
else if (choice.equals ("Green"))
{
y = 150;
g.setColor (Color.green);
}
g.fillOval (50, y, 30, 30);
} // method itemStateChanged
} // class listListener
} // class ChoicesList

Explanation / Answer

import java.awt.*;

//awt stands for abstract windowing tool kit.It is used in applications of GUI.

import java.applet.*;

//applet is used to develop web based applications

import java.awt.event.*;

//java.awt.xxxx packages are not included in the java.awt package

// Applet that draws different colored circles.

public class ChoicesList extends Applet

{

private List choices;

//declare a list named choices

private Graphics g;

                //Graphics is an abstract class. Hence, an instance g is created to access its members

public void init ()

//the init() method is started when the browser executes the program

{

//init() method definition

choices = new List (3, false);

//a list with three items is created with an object name

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote