Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 2 MCQs GUI and Event Handling

CSE406 — Advanced Java Programming 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Introduction to Swing Easy

    What is Swing in Java primarily used for?

  2. Question 2 of 60 JFrame and JPanel Easy

    Which Swing class represents a top-level application window?

  3. Question 3 of 60 JFrame and JPanel Easy

    What is the main purpose of a JPanel?

  4. Question 4 of 60 Swing components Easy

    Which Swing component is commonly used to display a clickable button?

  5. Question 5 of 60 Swing components Easy

    Which Swing component is used to display non-editable text?

  6. Question 6 of 60 Layout managers Easy

    What is the purpose of a layout manager?

  7. Question 7 of 60 Layout managers Easy

    Which layout manager places components in five regions: north, south, east, west, and center?

  8. Question 8 of 60 Color class Easy

    Which Java class is used to represent colors in Swing applications?

  9. Question 9 of 60 Color class Easy

    Which predefined constant represents the color red?

  10. Question 10 of 60 Font class Easy

    Which Java class is used to specify the typeface, style, and size of text?

  11. Question 11 of 60 Font class Easy

    Which constant is used with the Font class to create bold text?

  12. Question 12 of 60 Graphics class Easy

    Which class provides methods for drawing shapes and text in a component?

  13. Question 13 of 60 Programs to create Graphical User Interface Easy

    Which method is commonly overridden to perform custom drawing in a Swing component?

  14. Question 14 of 60 Event delegation model Easy

    In the event delegation model, which object receives and processes an event?

  15. Question 15 of 60 Event and event source Easy

    What is an event source?

  16. Question 16 of 60 Event listener interfaces Easy

    Which listener interface is commonly used to handle button-click events?

  17. Question 17 of 60 Registration and handling events Easy

    Which method registers an ActionListener with a JButton?

  18. Question 18 of 60 Mouse events Easy

    Which listener interface is used to handle events such as mouse clicks and mouse presses?

  19. Question 19 of 60 Key events Easy

    Which listener interface is used to handle keyboard events?

  20. Question 20 of 60 Anonymous class listeners Easy

    Why are anonymous classes often used for event listeners?

  21. Question 21 of 60 Introduction to Swing Medium

    Why should most Swing component updates be performed on the Event Dispatch Thread (EDT)?

  22. Question 22 of 60 JFrame and JPanel Medium

    A JPanel is added to a JFrame, but it does not appear after the frame becomes visible. Which action is most appropriate when components were added after the frame was displayed?

  23. Question 23 of 60 Swing components Medium

    A JTextField should accept input but must prevent the user from editing its contents. Which configuration achieves this?

  24. Question 24 of 60 Layout managers Medium

    A panel uses BorderLayout and adds two buttons without specifying constraints. Where will the buttons be placed?

  25. Question 25 of 60 Layout managers Medium

    A form requires labels and fields to align in rows and columns, with consistent control over horizontal and vertical gaps. Which layout manager is most suitable?

  26. Question 26 of 60 Color class Medium

    What color is produced by new Color(255, 128, 0)?

  27. Question 27 of 60 Font class Medium

    Which Font configuration creates bold italic text at size 18?

  28. Question 28 of 60 Graphics class Medium

    Inside a component's paintComponent(Graphics g) method, why is super.paintComponent(g) normally called first?

  29. Question 29 of 60 Graphics class Medium

    A component has width 200 and height 100. Which call draws a rectangle that fills the component's drawable area when the coordinate origin is at its top-left corner?

  30. Question 30 of 60 Programs to create Graphical User Interface Medium

    A GUI is built using a JFrame containing a panel and a button. Which sequence is generally appropriate before displaying the frame?

  31. Question 31 of 60 Event delegation model Medium

    In the Swing event delegation model, what happens when a user clicks a button?

  32. Question 32 of 60 Event and event source Medium

    In an ActionListener attached to a button, what does event.getSource() return?

  33. Question 33 of 60 Event listener interfaces Medium

    Which listener interface is used to respond to a button's activation through a mouse click or keyboard action?

  34. Question 34 of 60 Registration and handling events Medium

    A button has an ActionListener, but clicking it produces no response. Which missing operation is the most likely cause?

  35. Question 35 of 60 Mouse events Medium

    A drawing program should start a new shape only when the mouse button is pressed, continue tracking while it moves, and finish when it is released. Which listener combination is appropriate?

  36. Question 36 of 60 Mouse events Medium

    A component must respond only when the user double-clicks it. Which condition is appropriate inside a mouse event handler?

  37. Question 37 of 60 Key events Medium

    A game should react immediately when the user presses the left-arrow key, before the key is released. Which KeyListener method should be used?

  38. Question 38 of 60 Key events Medium

    A KeyListener is correctly registered on a text-area component, but it receives no keyboard events. Which condition is most likely missing?

  39. Question 39 of 60 Anonymous class listeners Medium

    Which code pattern registers an ActionListener without creating a separately named listener class?

  40. Question 40 of 60 Listener interface adapter Medium

    Why is MouseAdapter useful when a class needs to handle only mousePressed from MouseListener?

  41. Question 41 of 60 Introduction to Swing Hard

    A Swing application creates its JFrame, adds components, and calls setVisible(true) from the main thread while another thread modifies a JTable model. Which design best preserves Swing's threading guarantees?

  42. Question 42 of 60 JFrame and JPanel Hard

    A JPanel overrides paintComponent(Graphics g) but does not call super.paintComponent(g). The panel has a non-opaque background and is placed over another component. What is the most likely consequence?

  43. Question 43 of 60 Swing components Hard

    A disabled JButton is placed inside an enabled panel. A mouse click occurs at the button's coordinates. Which behavior is correct?

  44. Question 44 of 60 Layout managers Hard

    A BorderLayout container receives three components using BorderLayout.NORTH, BorderLayout.PAGE_START, and BorderLayout.CENTER. Which statement describes the result most accurately?

  45. Question 45 of 60 Layout managers Hard

    A GridBagLayout component has weightx = 0, fill = GridBagConstraints.HORIZONTAL, and a preferred width smaller than the available cell width. What happens when the container grows horizontally?

  46. Question 46 of 60 Color class Hard

    A color is constructed as new Color(300, -10, 128). What is the correct result?

  47. Question 47 of 60 Color class Hard

    A component calls setBackground(Color.RED) but still appears with its default background. Which condition most directly explains this behavior for a standard Swing component?

  48. Question 48 of 60 Font class Hard

    A program creates new Font("UnknownFamily", Font.BOLD, 18). Which statement is correct?

  49. Question 49 of 60 Font class Hard

    A component draws text using FontMetrics.getAscent() and getDescent(). If the baseline is at , where should the top of the normal text bounds approximately begin?

  50. Question 50 of 60 Graphics class Hard

    Inside paintComponent, a program stores the supplied Graphics object in a field and uses that field later from a timer to draw directly. What is the principal problem?

  51. Question 51 of 60 Graphics class Hard

    A custom component draws a filled rectangle at coordinates (0, 0) but the rectangle appears clipped or partly missing after scrolling. Which explanation is most accurate?

  52. Question 52 of 60 Programs to create Graphical User Interface Hard

    A form validates user input and then performs a network request directly inside an ActionListener. The request takes several seconds. What visible behavior is most likely?

  53. Question 53 of 60 Event delegation model Hard

    In the Swing event delegation model, what is the correct relationship among a source, an event, and a listener?

  54. Question 54 of 60 Event and event source Hard

    A single JButton has two different ActionListener objects registered. When the user activates the button, what should a correct implementation expect?

  55. Question 55 of 60 Event listener interfaces Hard

    A class implements MouseListener and needs behavior only when the mouse enters a component. What is required for compilation?

  56. Question 56 of 60 Registration and handling events Hard

    A JTextField has a KeyListener registered, but key callbacks are never called while a button has focus. Which change is most directly relevant?

  57. Question 57 of 60 Mouse events Hard

    A component receives a MouseEvent with getX() = 20 and getY() = 15 after the parent has been scrolled. What do these coordinates represent?

  58. Question 58 of 60 Mouse events Hard

    A component listens for mouseClicked and must distinguish a double-click from a single click. Which property should it inspect?

  59. Question 59 of 60 Key events Hard

    A KeyListener receives a key event for the uppercase character A. Which event type is designed to identify the physical key press independently of the character produced by modifiers?

  60. Question 60 of 60 Anonymous class listeners Hard

    An anonymous ActionListener captures a local variable named count and attempts to increment it inside actionPerformed. Why does this fail, and which replacement is valid?

That's unit 2

Answer a few questions and your score shows up here.