AJP Course Assignment 2
28 Questions
0 Views

AJP Course Assignment 2

Created by
@AdulatoryMeitnerium

Questions and Answers

In which package are Swing components defined?

  • javax.swing (correct)
  • javax.java.swing
  • java.javax.swing
  • javax.applet.swing
  • The super class of all swing buttons is –

  • JButton
  • ButtonGroup
  • AbstractButton (correct)
  • Button
  • Which of the following alignment is not possible for JLabel?

  • LEFT
  • TOP (correct)
  • LEADING
  • CENTER
  • Alignment constants of JLabel are part of –

    <p>SwingConstants class</p> Signup and view all the answers

    How will you set an icon for the JLabel?

    <p>Using setIcon() method</p> Signup and view all the answers

    Swing's text field is encapsulated by –

    <p>JComponent class</p> Signup and view all the answers

    How to give number of columns for JTextField?

    <p>Use setColumns() method</p> Signup and view all the answers

    What is the return type of getText() method of JButton class?

    <p>String</p> Signup and view all the answers

    How will you assign the string and icon both to the JButton?

    <p>Initialize them directly in the constructor</p> Signup and view all the answers

    Which event is generated when a JButton is pushed?

    <p>ActionEvent</p> Signup and view all the answers

    Immediate super class of JCheckBox is –

    <p>JComponent</p> Signup and view all the answers

    The constructor JCheckBox(true, 'YES') suggests that –

    <p>Checkbox is selected and displays the string 'YES' on it</p> Signup and view all the answers

    When JCheckBox is clicked, which event is generated?

    <p>ItemEvent</p> Signup and view all the answers

    How can we create Radio buttons?

    <p>Using JRadioButton class</p> Signup and view all the answers

    How to make the group of Radio buttons?

    <p>Using ButtonGroup class</p> Signup and view all the answers

    How to put the contents of the whole vector into the JComboBox?

    <p>Use the constructor of JComboBox</p> Signup and view all the answers

    How to prevent the drop-down list of JComboBox?

    <p>It is not possible</p> Signup and view all the answers

    Which method is used to define the tabs in the tabbed pane?

    <p>addTab()</p> Signup and view all the answers

    The scroll bar constants for scroll pane are defined in –

    <p>ScrollPaneConstants class</p> Signup and view all the answers

    Which of the following constants shows scroll bars always?

    <p>HORIZONTAL_SCROLLBAR_ALWAYS</p> Signup and view all the answers

    JScrollPane is an immediate sub-class of –

    <p>JComponent</p> Signup and view all the answers

    Is it possible to add an array of objects to trees? How?

    <p>Yes, using one of its constructor forms</p> Signup and view all the answers

    Which items can't we directly add to JTree using its constructor?

    <p>Array of objects</p> Signup and view all the answers

    When a tree is expanded, which event is generated?

    <p>TreeExpansionEvent</p> Signup and view all the answers

    Which method is used to translate a mouse click on a specific point of the tree to a tree path?

    <p>getPathForLocation()</p> Signup and view all the answers

    The TreeNode is –

    <p>A class</p> Signup and view all the answers

    The TreeExpansionEvent class is defined in –

    <p>javax.swing.event package</p> Signup and view all the answers

    The TreeExpansionListener interface provides the following method –

    <p>treeExpanded()</p> Signup and view all the answers

    Study Notes

    Swing Components and Classes

    • Swing components are defined in the javax.swing package.
    • The superclass of all Swing buttons is AbstractButton.
    • JLabel cannot have a TOP alignment option; only LEFT, CENTER, and LEADING are valid alignments.
    • Alignment constants for JLabel are part of the SwingConstants interface.

    JLabel and JTextField

    • To set an icon for JLabel, use the setIcon() method.
    • Swing's text field is encapsulated by the JTextComponent class.
    • Number of columns for JTextField can be defined using the setColumns() method or directly within the constructor.

    JButton Functionalities

    • The return type of getText() method from the JButton class is String.
    • To assign both string and icon to a JButton, use the setIconText() method.
    • Pushing a JButton generates an ActionEvent.

    JCheckBox and Radio Buttons

    • The immediate superclass of JCheckBox is JToggleButton.
    • Constructor JCheckBox(true, "YES") indicates that the checkbox is selected and displays "YES".
    • Clicking a JCheckBox generates an ItemEvent.
    • Radio buttons are created using the JRadioButton class and grouped with the ButtonGroup class.

    JComboBox and ScrollPane

    • To add content from a whole vector into a JComboBox, use the JComboBox constructor.
    • To prevent a JComboBox drop-down list, use a method specifically created for prevention or effects within the constructor.
    • Tabs in the tabbed pane are defined using the addTab() method.
    • Scroll bar constants for a scroll pane are defined in the ScrollPaneConstants class.
    • HORIZONTAL_SCROLLBAR_ALWAYS shows horizontal scroll bars at all times.

    JScrollPane and JTree

    • JScrollPane is an immediate subclass of JComponent.
    • Adding an array of objects to trees is possible using a specific form of the constructor.
    • Directly adding arrays to JTree using its constructor is not possible, while vectors and hash tables can be added.
    • Expanding a tree generates a TreeExpansionEvent.

    TreeNode and Event Handling

    • TreeNode is an interface.
    • The TreeExpansionEvent class is defined in the javax.swing.event package.
    • The TreeExpansionListener interface includes the treeExpanded() method.

    Miscellaneous

    • Handling mouse clicks on a specific point of the tree can be interpreted to a tree path using the getPathForLocation() method.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge on Swing components in Java with this assignment. You'll be quizzed on the various classes, packages, and functionalities associated with Java Swing. Perfect for AJP course students!

    More Quizzes Like This

    Use Quizgecko on...
    Browser
    Browser