Download presentation
Presentation is loading. Please wait.
Published byElaine Harper Modified over 8 years ago
1
Clicker quiz 11/5/13 CSE 1102 Fall 2013
2
A. a FlowLayout B. a BorderLayout C. a GridGrouping D. a JSplitPane E. a GridLayout Suppose we want to to lay things out in a Frame such that there is panel in the center, with other panels to the right, below, and to the left. The most straightforward way to do this it to use:
3
A. the event source B. the event listener C. the event responder D. it doesn’t fit this model E. it doesn’t use events Suppose we add a slider to our program using a JSlider. To make it useful, we need to deal with events associated with that slider. Using our “standard” source-listener-responder event handling model, the JSlider is
4
A. a group of buttons that will be contiguous on the screen B. a group of buttons that allows at most one to be selected C. a group of buttons that can only have a single listener D. all of the above E. none of the above One of the API classes introduced in Chapter 8 was ButtonGroup, a class that will be associated with a group of (surprise, surprise) Buttons. The ButtonGroup can be used to set up
5
Clicker questions 11/5/13 CSE 1102 Fall 2013
6
A. Four pairs, and it’s obvious. B. Two sets of four, and it’s obvious. C. It’s not obvious, but it is consistent. D. The groupings could be completely arbitrary. E. It’s always OK to just try them out. How do you imagine the buttons are grouped?
7
A. They will be on the bottom, one over another B. They will be on the left side, one over another; C. They will be on the bottom in a single row; D. They will not show up on the screen E. None of the above is true 1.public ColorButtonPanel extends javax.swing.JPanel { 2.private JRadioButton _redButton; 3. private JRadioButton _blueButton; 4. private JRadioButton _greenButton; 5.public ColorButtonPanel(){ 6. _redButton = new JRadioButton("red",true); 7. _blueButton = new JRadioButton("blue"); 8. _greenButton = new JRadioButton("green"); 9. } 10.... } Suppose we add a ColorButtonPanel to JFrame _myFrame using _myFrame.add(new ColorButtonPanel(), "South"); Assuming we added something else to the Center of _myFrame, where will the buttons show up on the screen?
8
A. Neither button is seen as selected (filled circle) B. The red button is seen as selected, the blue not; C. The blue button is seen as selected, the red not selected D. Both buttons will be selected E. The buttons will not be changed no matter where I click 1.public class ColorButtonPanel extends javax.swing.JPanel { 2.private JRadioButton _redButton; 3. private JRadioButton _blueButton; 4.public ColorButtonPanel(){ 5. _redButton = new JRadioButton("red",true); 6. _blueButton = new JRadioButton("blue"); 7. this.add(_redButton); 8. this.add(_blueButton); 9. } 10.... } Suppose we add a ColorButtonPanel to JFrame _myFrame using _myFrame.add(new ColorButtonPanel, "South"); What happens when I click on the Button labeled "blue"?
9
A. You need to add an ActionListener to the ButtonGroup B. You need to add an ActionListener to ColorButtonPanel C. You need to add a ItemListener to the ColorButtonPanel D. You need to add an ActionListener to each JRadioButton E. More than one of the solutions above would work 1.public class ColorButtonPanel extends javax.swing.JPanel { 2.private JRadioButton _redButton; 3. private JRadioButton _blueButton; 4. private ButtonGroup _myGroup; 5.public ColorButtonPanel(){ 6. _redButton = new JRadioButton("red",true); 7. _blueButton = new JRadioButton("blue"); 8. _myGroup = new ButtonGroup(); 9. this.add(_redButton); 10. this.add(_blueButton); 11. _myGroup.add(_redButton); 12. _myGroup.add(_blueButton); 13. } 14.... } What code do I need so that something happens in my program (not just to the appearance of the buttons) when I click on one of them?
10
A. this.addMouseListener(new MouseStuff(this)); B. this.addMouseListener(this); C. this.addMouseAdapter(new MouseStuff(this)); D. this.addMouseAdapter(this); E. None of the above 1.public class MickeyPanel extends javax.swing.JPanel { 2. public MickeyPanel(){ 3.... 4. ???? 5. } 6. private class MouseStuff extends MouseAdapter { 7. private JPanel _myPanel; 8. public MouseStuff(JPanel panel){ 9. _myPanel = panel; 10. } 11. public void mouseClicked(MouseEvent e) { 12. _myPanel.doSomething(); 13. } 14. }} What code do I need in line 4 that would install a MouseStuff as a MouseListener for MickeyPanel?
11
A. this.addMouseListener(new MouseStuff(this)); B. this.addMouseListener(this); C. this.addMouseAdapter(new MouseStuff(this)); D. this.addMouseAdapter(this); E. None of the above 1.public class MickeyPanel extends javax.swing.JPanel { 2. public MickeyPanel(){ 3.... 4. 5. } 6. public void addListener{Object anObject} 7. { 8. 9. } 10. 11. 12. 13. 14. What code do I need in line 4 that would install a MouseStuff as a MouseListener for MickeyPanel?
12
Suppose it was desired to build a GUI offering the user a choice between a slider, or a numeric entry field to enter data to be entered into the same variable. Which answer best describes the consequences this has for sources, listeners and responders? A. It follows our “standard pattern”: Each responder class includes a private class for its listener. An instance of that listener is to be registered with the class that contains it. A method in the private class is called upon user activation of that affordance. This method sends a message to the responder object(s). B. The slider and the numeric entry field have to be peer objects. C. It is probably efficient of code to have both affordances sharing a container. D. It’s not possible to code this. E. The standard pattern’s meaning now includes that GUI components (sources) get updated even when the user has not “touched” them.
13
Suppose it was desired to build a GUI showing the user radio buttons whose groupings changed in response to user choices. Which answer best describes the consequences this has for layout, grouping, sources, listeners and responders? A. It follows our “standard pattern”: Each responder class includes a private class for its listener. An instance of that listener is to be registered with the class that contains it. A method in the private class is called upon user activation of that affordance. This method sends a message to the responder object(s). B. All of the buttons have to be peer objects. C. It is probably efficient of code to have all the buttons sharing a container. D. It’s not possible to code this. E. The group affiliation of buttons can be dynamic: New groups can be made.
14
Suppose it was desired to build a GUI showing the user radio buttons whose groupings changed in response to user choices. How do we know the old groupings are removed in time for the next user action? A.We can invoke the garbage collector. B. If there are no pointers to the old groups, the garbage collector will remove them. C. Removing a common container will remove the groups because these form a composite. D. It’s not possible to code this. E. None of the above is adequate, so ButtonGroup has a remove method.
15
Development system software exists that can create Java code for GUIs, automatically, when presented correctly with the desired user interface widgets. Which reason below best captures why students need to know how to write this Java themselves? A.The automatically generated code might contain bugs. B. The system automatically generating the code might be too limiting. C. When employing a combination of several technologies, it can be necessary to examine how they work together, which can require inspecting the code. D. There is no such automatic code generation. E. You may want to mesh some new idea into what is automatically created, and that will involve working with the automatically generated code.
16
A. You are already using the desired listener as an ActionListener for something else B. You want to associate the button actions with becoming deselected C. You want to reduce the number of messages sent to the listeners D. You want actions to be associated with both becoming selected and deselected E. All of the above are circumstances where ItemListener is a better choice If I add an ItemListener to a Button in a ButtonGroup, it will invoke itemStateChangeditemStateChanged(ItemEvent) in that listener whenever the button changes from selected to deselected or vice-versa.ItemEvent This might be preferable to using an ActionListener in some circumstances. Which of the following is not one of these circumstances?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.