Short Q2 Flashcards
Differentiate clearly between the mouseMotionListener and MouseListener
MouseListener is used when the mouse is stable while handling a event. MouseMotionListener is when the mouse is in motion
Explain the role of each of the following:
ActionListener
ItemListener
ActionListener - User clicks a button, presses return while typing in a text field, or chooses a menu item.
ItemListener = ItemListener is an interface that listens for the item event, basically it refers to the item selection
Outline the function of each of the following:
setVisible
getContentPane-
setVisible- we must use this method to make it appear on the screen as frames are invisible by default.
getContentPane- The getContentPane() method retrieves the content pane layer so that you can add an object to it
Describe the function of the following:
JTextArea
JTextField
JTextArea - Allows uses to enter multiple lines of Text
JTextField - A text field is an area a user can type in characters
Describe the function of the following:
JOptionPane
JScrollPane
JOptionPane - Create and customize several different kinds of dialog
JScrollPane - .If you want your users to be able to see content that exceeds the screen display area, you must place the component inside of a JScrollPane to support scrolling to the extra content
Describe the role of each
SetJMenuBar
setLookAndFeel
SetJMenuBar - Is used to add a menu bar to a top-level contrainer such as a JFrame
SetLookAndFeel- Look” refers to the appearance of GUI widgets (more formally, JComponents ) and “feel” refers to the way the widgets behave
Compare and contrast the following layout managers in gui:
BoxLayout
BorderLayout
GridLayout
Box Layout - It is the default layout in JFrame. It can position components in five different regions like top, bottom, left, right and center.
Border Layout - puts components in a square at one of the positions of North, South, East, West and center
Grid Layout - puts components in a rectangular grid
Using java code statements declare a JComboBox called carMakeList containing Fiat,Volskwagon and Mercedes
string[]carMakeList = new String{"Fiat","volkswagon","Mercedes"}. JComboBoxcarMakeList = new JComboBox <>(carMakeList);
How to retrieve the input text entered by user in a JPasswordField components
passwordField = new JPasswordField(10); passwordField.setActionCommand(OK); passwordField.addActionListener(this);