13
Clicker quick questions 10/17/13 CSE 1102 Fall 2013

Clicker quick questions 10/17/13 CSE 1102 Fall 2013

Embed Size (px)

Citation preview

Page 1: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

Clicker quick questions10/17/13

CSE 1102 Fall 2013

Page 2: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. They needed an Ellipse that would work on a smart phone

B. They wanted an Ellipse that could move around the screen

C. They wanted an Ellipse that could draw itself [CORRECT]

D. StupidEllipse was already taken

E. None of the above

In chapter 7, why do the authors define a SmartEllipse class?

Page 3: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

Modifier and Type Method and Description

Rectangle2DgetBounds2D() Returns a high precision and more accurate bounding box of the Shape than the getBounds method.

doublegetHeight() Returns the height of the framing rectangle in double precision.

doublegetWidth() Returns the width of the framing rectangle in double precision.

doublegetX() Returns the X coordinate of the upper-left corner of the framing rectangle in double precision.

doublegetY() Returns the Y coordinate of the upper-left corner of the framing rectangle in double precision.

booleanisEmpty() Determines whether the RectangularShape is empty.

voidsetFrame(double x, double y, double w, double h) Sets the location and size of the framing rectangle of this Shape to the specified rectangular values.

Methods inherited from class java.awt.geom.Ellipse2Dcontains, contains, equals, getPathIterator, hashCode, intersects

Methods inherited from class java.awt.geom.RectangularShapeclone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, intersects, setFrame setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal

Page 4: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. JWindow

B. JFrame

C. JPanel [CORRECT]

D. JContainer

E. Canvas

The thing you draw on in Swing is _______, or one of its subclasses.

Page 5: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

What is the purpose of line 2?

A. It calls the superclass constructor

B. It ensures that the code in paintComponent(Graphics) of its superclass is executed as soon as this method is called [CORRECT]

C. It ensures that the code in paintComponent(Graphics) of its superclass is executed after the code in this method

D. It calls the default paintComponent(Graphics) for this class

E. None of the above

Consider the following code fragment (line numbers added) from BallApp – assume java.awt.* included:

1. public void paintComponent(Graphics aBrush) {

2. super.paintComponent(aBrush);

3. ... // more code goes here

4. }

Page 6: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

Clicker questions10/17/13

CSE 1102 Fall 2013

Page 7: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. paintComponent calls repaint()

B. paintComponent has a parameter of type Graphics [CORRECT]

C. repaint() calls paintComponent

D. paintComponent is a method of the Graphics class

E. None of the above

How are Graphics, paintComponent, and repaint() related?

Page 8: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. It places a Red Ball in the JFrame

B. It provides a place to draw things within the frame [CORRECT]

C. It opens a window on the display

D. It puts a banner message on the screen

E. none of the above

1. public class BallApp extends javax.swing.JFrame {2. public BallApp (String title) {3. super(title);4. this.setSize(600, 450);5. this.setDefaultCloseOperation(

javax.swing.JFrame.EXIT_ON_CLOSE);6. this.add(new BallPanel());7. this.setVisible(true);8. }9. public static void main (String [ ] args) {10. BallApp app = new BallApp (11. "*Now* you can change the banner!");12. }13.}

What is the purpose of this BallPanel added in line 6?

Page 9: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. When the BallPanel is constructed

B. When the user invokes it directly

C. When the panel's container causes it to be invoked [CORRECT]

D. When the panel asks for it to be invoked [CORRECT]

E. More than one of the above is true [CORRECT]

1. public class BallPanel extends javax.swing.JPanel {2. private SmartEllipse _ball; // components3. public BallPanel () {4. super();5. this.setBackground(java.awt.Color.white);6. _ball = new SmartEllipse (java.awt.Color.red); 7. _ball.setLocation(75,75);8. _ball.setSize(60,60);9. }10. public void paintComponent (java.awt.Graphics aBrush) {11. super.paintComponent(aBrush);12. java.awt.Graphics2D betterBrush = 13. (java.awt.Graphics2D) aBrush;14. _ball.fill(betterBrush);15. }16.}

When does paintComponent (lines 10-15) get invoked?

Page 10: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. It identifies the type of aBrush

B. It provides an alternative to using aBrush

C. It is a parameter to pass to aBrush

D. It produces a version of aBrush that is really a Graphics2D [CORRECT]

E. None of the above is true

1. public class BallPanel extends javax.swing.JPanel {2. private SmartEllipse _ball; // components3. public BallPanel () {4. super();5. this.setBackground(java.awt.Color.white);6. _ball = new SmartEllipse (java.awt.Color.red); 7. _ball.setLocation(75,75);8. _ball.setSize(60,60);9. }10. public void paintComponent (java.awt.Graphics aBrush) {11. super.paintComponent(aBrush);12. java.awt.Graphics2D betterBrush = 13. (java.awt.Graphics2D) aBrush;14. _ball.fill(betterBrush);15. }16.}

What does (java.awt.Graphics2D) do in line 13?

Page 11: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. It instantiates the color of aBrush

B. It provides a starting point if we want to change something's color

C. It specifies the color that the SmartEllipse should be filled with or drawn

D. It specifies the color that aBrush was before we draw or fill a SmartEllipse [CORRECT]

E. None of the above

1. // SmartEllipse continued2. public void fill (java.awt.Graphics2D aBetterBrush){3. java.awt.Color savedColor = aBetterBrush.getColor();4. aBetterBrush.setColor(_fillColor);5. aBetterBrush.fill(this); // paint a solid ellipse6. aBetterBrush.setColor(savedColor);7. }8. public void draw (java.awt.Graphics2D aBrush) {9. java.awt.Color savedColor = aBrush.getColor();10. aBrush.setColor(_borderColor);11. java.awt.Stroke savedStroke = aBrush.getStroke();12. aBrush.setStroke(new java.awt.BasicStroke(STROKE_WIDTH));13. aBrush.draw(this);14. aBrush.setStroke(savedStroke);15. aBrush.setColor(savedColor);16. }17.}

In these methods, what is the purpose of the variable savedColor?

Page 12: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. Window

B. Frame

C. JPanel

D. JFrame [CORRECT]

E. JWindow

What is the basic window class in Swing?

Page 13: Clicker quick questions 10/17/13 CSE 1102 Fall 2013

A. Frame

B. JComponent

C. Container

D. Component

E. None of the above

What is the least common ancestor of JFrame and JPanel?