110 likes | 293 Views
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 9. TOPICS TO COVER. FlowLayout class ( java.awt.FlowLayout ) Default for javax.swing.JPanel Components are placed from left to right in order they are added. Automatically places components onto next row, if row is full. FlowLayout ()
E N D
TOPICS TO COVER FlowLayout class (java.awt.FlowLayout) • Default for javax.swing.JPanel • Components are placed from left to right in order they are added. • Automatically places components onto next row, if row is full. • FlowLayout() • FlowLayout(int) // alignment Row positioning options • FlowLayout.LEFT • FlowLayout.RIGHT • FlowLayout.CENTER (default) • void setAlignment(int) // alignment • intgetAlignment()
TOPICS TO COVER BorderLayout class (java.awt.BorderLayout) • Default for javax.swing.JFrame • Arranges components in five regions • Places upto five components in a container one in each region. • Automatically displaces previous component, if component is already occupied in the position. • BorderLayout() • BorderLayout(int, int) // horizontal gap, vertical gap Regions • BorderLayout.NORTH • BorderLayout.SOUTH • BorderLayout.EAST • BorderLayout.WEST • BorderLayout.CENTER
TOPICS TO COVER GridLayout class (java.awt.GridLayout) • Divides container into a grid so that components can be placed in rows and columns. • Each component has same width and height. • GridLayout() • GridLayout(int, int) // rows, columns • GridLayout(int, int, int, int) // rows, columns, horizontal gap, vertical gap • intgetColumns() • intgetHgap() • intgetRows() • intgetVgap() • void setColumns(intcols) • void setHgap(inthgap) • void setRows(introws) • void setVgap(intvgap)
TOPICS TO COVER Handling Events • Interaction of user with GUI components is called event. • Java events are part of the Java AWT package. • The code that performs a task in response to an event is called an event handler. • Overall process of responding to events is known as event handling. • GUIs are event driven. • The sourceof an event is the component that causes that event to occur. • The listenerof an event is an object that receives the event and processes it appropriately. Event Handling Process • When an event is triggered, the JAVA runtime first determines its source and type. • If a listener for this type of event is registered with the source, an event object is created. • For each listener to this type of an event, the JAVA runtime invokes the appropriate event handling method to the listener and passes the event object as the parameter.
Topics To Cover Sources of Events • Button • Checkbox • Choice • List • Menu Item • Scrollbar • Text Components • Window
TOPICS TO COVER Main Event Classes in java.awt.event • ActionEvent • Generated when a button is pressed, a list is double-clicked, or a menu item is selected. • String getActionCommand() // returns string containing event source caption • ComponentEvent • Generated when a component is hidden, moved, resized, or becomes visible. • String getComponent().getClass().getName() • FocusEvent • Generated when a component gains or loses keyboard focus. • .getComponent().getClass().getName() • ItemEvent • Generated when a check box or a list item is clicked; also occurs when a choice selection is made or a checkable menu is selected or deselected. • KeyEvent • Generated when input is received from the keyboard. • MouseEvent • Generated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component. • TextEvent • Generated when the value of a textarea or textfield is changed. • WindowEvent • Generated when a window os activated, closed, deactivated, deiconified, iconified, opened, or quit.
TOPICS TO COVER Main Event Classes in java.awt.event • ActionEvent • Generated when a button is pressed, a list is double-clicked, or a menu item is selected. • ComponentEvent • Generated when a component is hidden, moved, resized, or becomes visible. • FocusEvent • Generated when a component gains or loses keyboard focus. • ItemEvent • Generated when a check box or a list item is clicked; also occurs when a choice selection is made or a checkable menu is selected or deselected. • KeyEvent • Generated when input is received from the keyboard. • MouseEvent • Generated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component. • TextEvent • Generated when the value of a textarea or textfield is changed. • WindowEvent • Generated when a window os activated, closed, deactivated, deiconified, iconified, opened, or quit.
Topics To Cover Event Listener Methods in Interfaces • ActionListener • void actionPerformed (ActionEventae) • ComponentListener • void componentResized (ComponentEventce) • void componentMoved (ComponentEventce) • void componentShown (ComponentEventce) • void componentHidden (ComponentEventce) • FocusListener • void focusGained (FocusEventfe) • void focusLost (FocusEventfe) • ItemListener • void itemStateChanged (ItemEventie) • KeyListener • void keyPressed (KeyEventke) • void keyReleased (KeyEventke) • void keyTyped (KeyEventke)
Topics To Cover Event Listener Methods in Interfaces: • MouseListener • void mouseClicked (MouseEvent me) //pressed or released on a component • void mousePressed(MouseEvent me) • void mouseReleased (MouseEvent me) • MouseMotionListener • void mouseDragged (MouseEvent me) • void mouseMoved (MouseEvent me) //no buttons have been pushed • TextListener • void textValueChanged(TextEventte) • WindowListener • void windowActivated (WindowEvent we) • void windowClosed (WindowEvent we) • void windowClosing (WindowEvent we) • void windowDeactivated (WindowEvent we) • void windowDeiconified (WindowEvent we) //from a minimized to a normal state • void windowIconified (WindowEvent we) //from a normal to a minimized state • void windowOpened (WindowEvent we)