Question: Applets and More 1) In the following code, which line has an error? 1 public class TestApplet extends JApplet 2 { 3 public void init()

Applets and More

1) In the following code, which line has an error?

1 public class TestApplet extends JApplet

2 {

3 public void init()

4 {

5

super.JApplet();

6JLabel label = new JLabel("Test label");

7 setLayout(new FlowLayout());

8 add(label);

9 }

10 }

A) 1 B) 3 C) 5 D) There are no errors

2) Look at the following applet code:

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 int[] xCoords = {20, 20, 60, 100, 140, 140, 100, 60};

12 int[] ycoords = {20, 100, 140, 140, 100, 60, 20, 20};

13 super.paint(g);

14 g.setColor(Color.YELLOW);

15 g.fillPolygon(xCoords, yCoords, 8);

16 g.setColor(color.BLACK);

17 g.setFont(new Font("SansSerif", Font.BOLD, 35));

18 g.drawString("SLOW", 35, 95);

19 }

20 }

How many vertices does the polygon have?

A) 5 B) 6 C) 7 D) 8

3) Look at the following applet code:

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet 2

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 int[] xCoords = {20, 20, 60, 100, 140, 140, 100, 60};

12 int[] ycoords = {20, 100, 140, 140, 100, 60, 20, 20};

13 super.paint(g);

14 g.setColor(Color.YELLOW);

15 g.fillPolygon(xCoords, yCoords, 8);

16 g.setColor(color.BLACK);

17 g.setFont(new Font("SansSerif", Font.BOLD, 35));

18 g.drawString("SLOW", 35, 95);

19 }

20 }

What is the color of the polygon?

A) White B) Yellow C) Black D) None of the above

4) Look at the following applet code.

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 int[] xCoords = {20, 20, 60, 100, 140, 140, 100, 60};

12 int[] ycoords = {20, 100, 140, 140, 100, 60, 20, 20};

13 super.paint(g);

14 g.setColor(Color.YELLOW);

15 g.fillPolygon(xCoords, yCoords, 8);

16 g.setColor(color.BLACK);

17 g.setFont(new Font("SansSerif", Font.BOLD, 35));

18 g.drawString("SLOW", 35, 95);

19 }

20 } What will be the coordinates of the third point of the polygon?

A) (60, 140) B) (140, 60) C) (100, 140) D) (140, 100)

5) In the following code that uses a Swing GUI, which line has an error?

1 public class TestApplet extends Applet

2 {

3 public void init()

4 {

5 JLabel label = new JLabel("Test label");

6 setLayout(new FlowLayout());

7 add(label);

8 }

9 }

A) 1 B) 3 C) 5 D) There are no errors.

6) Look at the following applet code:

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 super.paint(g);

12 g.setColor(Color.YELLOW);

13 g.fillOval(100, 100, 50, 50);

14 g.setColor(Color.BLACK);

15 g.setFont(new Font("SansSerif", Font.BOLD, 35));

16 g.drawString("SLOW", 110, 110);

17 }

18 } Which line sets the color that will be used to draw "SLOW"?

A) 7 B) 12 C) 14 D) 16

7) Look at the following applet code:

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 super.paint(g);

12 g.setColor(Color.YELLOW);

13 g.fillOval(100, 100, 50, 50);

14 g.setColor(Color.BLACK);

15 g.setFont(new Font("SansSerif", Font.BOLD, 35));

16 g.drawString("SLOW", 110, 110);

17 }

18 } What shape will the oval have?

A) Oblong, width greater than height

B) Oblong, width less than height

C) Circle

D) Cannot tell

8) Look at the following applet code:

1 import javax.swing.*;

2 import java.awt.*;

3 public class GraphicsTest extends JApplet

4 {

5 public void init()

6 {

7 getContentPane().setBackground(Color.WHITE);

8 }

9 public void paint(Graphics g)

10 {

11 super.paint(g);

12 g.setColor(Color.YELLOW);

13 g.fillOval(100, 100, 50, 50);

14 g.setColor(Color.BLACK);

15 g.setFont(new Font("SansSerif", Font.BOLD, 35));

16 g.drawString("SLOW", 110, 110);

17 }

18 }

What will be the coordinates of the center of the oval?

A) (100, 100) B) (50, 50) C) (100, 50) D) (125, 125)

9) Given the following code, how many times per second will the TimerListener event be generated?

Timer timer = new Timer(500, new TimerListener());

A) 5 B) 50 C) 2 D) 500

10) In the following code, what does getDocumentBase()return?

play(getDocumentBase(), "mysound.wav");

A) A URL object containing the location of the applet's .class file

B) A URL object containing the location of the HTML file that invoked the applet

C) The HTML location "mysound.wav"

D) The sound file itself

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!