Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clicker questions 10/24/13 CSE 1102 Fall 2013. θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y;

Similar presentations


Presentation on theme: "Clicker questions 10/24/13 CSE 1102 Fall 2013. θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y;"— Presentation transcript:

1 Clicker questions 10/24/13 CSE 1102 Fall 2013

2 θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y; D.tan(θ) = y/x; [CORRECT] E.None of the above

3 What is the effect of line 2? Between lines 2 and 6, _____________ A._body and _tail are rotated about their center points and filled B.anything filled with aBrush will be rotated around its center point C.anything filled with aBrush will be rotated around the Fish’s center point [CORRECT] D.All of the above are true Consider the following code fragment (line numbers added) from Fish; assume java.awt.* included: 1.public void fill(Graphics2D aBrush) { 2. aBrush.rotate(_rotation, this.getCenterX(), this.getCenterY()); 3. _body.fill(aBrush); 4. _tail.fill(aBrush); 5.... 6. aBrush.rotate(-_rotation, this.getCenterX(), this.getCenterY()); 7.}

4 Suppose we leave off line 5. What will be the effect? A.No effect, the animation runs the same B.The Fish will be rotated further on each tick of the timer C.It depends on the number of Fish [CORRECT] D.None of the above are true Consider the following code fragment (line numbers added) from Fish; assume java.awt.* included: 1.public void fill(Graphics2D aBrush) { 2. aBrush.rotate(_rotation, this.getCenterX(), this.getCenterY()); 3. _body.fill(aBrush); 4. _tail.fill(aBrush); 5. aBrush.rotate(-_rotation, this.getCenterX(), this.getCenterY()); 6.}

5 What do I need to do to get this to work ie to move the Fish on the screen? A.Make sure _myPanel is the FishPanel the Fish is in B.Register the Fish as an ActionListener of the Timer C.Both A and B. [CORRECT] D.There will be a compiler error, so it won’t work Suppose I rewrite Fish, declaring that it implements ActionListener, and includes the following code: 1.public class Fish implements Mover, ActionListener 2.... // some other Fish code 3. public void actionPerformed(ActionEvent e){ 4.this.move(); 5. _myPanel.repaint(); 6.} 7.}

6 __________ is visible to code in the inner class (at ????, say): A.All protected methods and protected instance variables of the outer class B.All public methods and public instance variables of the outer class C.All methods and all public instance variables of the outer class D.All methods and instance variables of the outer class. [CORRECT] E.None of the above is true Suppose I define an inner class, as was done in MoveTimer. The code in the inner class can access: 1.public class Outer extends SomeClass implements SomeInterface{ 2.... 3. private class Inner extends AnotherClass { 4. ???? 5. } 6.}

7 This code illustrates which point about inner classes A.Inner classes have no constructors B.Instance variables of the outer class are visible to instances of the inner class [CORRECT] C.super can be called with null as a parameter D.An inner class is the subclass of its outer class. E.None of the above is true Consider MoveTimer: 1.public class MoveTimer extends javax.swing.Timer{ 2. private Mover _mover; 3. public MoveTimer(int anInterval, Mover aMover){ 4. super(anInterval, null); 5. _mover = aMover; 6. this.addActionListener(new MoveListener()); 7. } 8. private class MoveListener implements ActionListener { 9. public void actionPerformed(ActionEvent e) { 10. _mover.move(); 11. } 12. } 13.}

8 Random behavior : import java.lang.Math ; … if(Math.random() >.5) { do something } else { do something else } Another cool Math thing

9 About repaint Both Component and JComponent have repaint methods. Component has –public void repaint() –public void repaint(long millisecondsDelay) –public void repaint(int x, int y, int width, int height) –public void repaint(long millisecondsDelay, int x, int y, int width, int height)

10 More about repaint JComponent has –public void repaint(Rectangle r) –public void repaint(long timeWithin, int x, int y, int width, int height)

11 This code invokes which repaint method? A.The one in JComponent, because it extends JPanel. B.The one in JComponent, because the keyword “this” is used. C.The one in Component, because that is the highest in the inheritance hierarchy. D.The one in Component, because there are no arguments. E.Both, because the one in JComponent invokes the one in Component. About repaint: 1.public class FishPanel extends javax.swing.JPanel{ 2. 3. public FishPanel(){ 4. … 5. } 6. private void move() { 7. … 8. this.repaint(); 9. } 10. } 11.}

12 If the paintComponent method is misspelled, what happens? A.repaint works according to its specification. B.There is a runtime error message about a Null Pointer for the method. C.There is a compile time error message about not implementing a method for JPanel. D.The display looks fine until it is resized, or changes from covered to uncovered. [CORRECT] E.None of the above. More about repaint: 1.public class FishPanel extends javax.swing.JPanel{ 2. 3. public FishPanel(){ 4. … 5. } 6. private void move() { 7. … 8. this.repaint(); 9. } 10. } 11.}


Download ppt "Clicker questions 10/24/13 CSE 1102 Fall 2013. θ (x,y) (0,0) What is the relationship between θ and (x,y) ? A.y = mx + b B.θ = x 2 + y 2 C.tan(θ) = x/y;"

Similar presentations


Ads by Google