Advanced OOP MCS3 OOP BSCS 3 Lecture 9
Advanced OOP MCS-3 OOP BSCS 3 Lecture # 9
TOPICS TO COVER Flow. Layout class (java. awt. Flow. Layout) • 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. • Flow. Layout() • Flow. Layout(int) // alignment Row positioning options • Flow. Layout. LEFT • Flow. Layout. RIGHT • Flow. Layout. CENTER (default) • void set. Alignment(int) • int get. Alignment() // alignment
TOPICS TO COVER Border. Layout class (java. awt. Border. Layout) • 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. • Border. Layout() • Border. Layout(int, int) Regions • Border. Layout. NORTH • Border. Layout. SOUTH • Border. Layout. EAST • Border. Layout. WEST • Border. Layout. CENTER // horizontal gap, vertical gap
TOPICS TO COVER Grid. Layout class (java. awt. Grid. Layout) • Divides container into a grid so that components can be placed in rows and columns. • Each component has same width and height. • Grid. Layout() • Grid. Layout(int, int) // rows, columns • Grid. Layout(int, int) // rows, columns, horizontal gap, vertical gap • • int get. Columns() int get. Hgap() int get. Rows() int get. Vgap() void set. Columns(int cols) void set. Hgap(int hgap) void set. Rows(int rows) void set. Vgap(int vgap)
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 source of an event is the component that causes that event to occur. • The listener of 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 • Action. Event • Generated when a button is pressed, a list is double-clicked, or a menu item is selected. • String get. Action. Command() // returns string containing event source caption • Component. Event • Generated when a component is hidden, moved, resized, or becomes visible. • String get. Component(). get. Class(). get. Name() • Focus. Event • Generated when a component gains or loses keyboard focus. • . get. Component(). get. Class(). get. Name() • Item. Event • 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. • Key. Event • Generated when input is received from the keyboard. • Mouse. Event • Generated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component. • Text. Event • Generated when the value of a textarea or textfield is changed. • Window. Event • Generated when a window os activated, closed, deactivated, deiconified, opened, or quit.
TOPICS TO COVER Main Event Classes in java. awt. event • Action. Event • Generated when a button is pressed, a list is double-clicked, or a menu item is selected. • Component. Event • Generated when a component is hidden, moved, resized, or becomes visible. • Focus. Event • Generated when a component gains or loses keyboard focus. • Item. Event • 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. • Key. Event • Generated when input is received from the keyboard. • Mouse. Event • Generated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component. • Text. Event • Generated when the value of a textarea or textfield is changed. • Window. Event • Generated when a window os activated, closed, deactivated, deiconified, opened, or quit.
TOPICS TO COVER Event Listener Methods in Interfaces • Action. Listener • void action. Performed (Action. Event ae) • Component. Listener • • void component. Resized (Component. Event ce) void component. Moved (Component. Event ce) void component. Shown (Component. Event ce) void component. Hidden (Component. Event ce) • Focus. Listener • void focus. Gained (Focus. Event fe) • void focus. Lost (Focus. Event fe) • Item. Listener • void item. State. Changed (Item. Event ie) • Key. Listener • void key. Pressed (Key. Event ke) • void key. Released (Key. Event ke) • void key. Typed (Key. Event ke)
TOPICS TO COVER Event Listener Methods in Interfaces: • Mouse. Listener • void mouse. Clicked (Mouse. Event me) • void mouse. Pressed(Mouse. Event me) • void mouse. Released (Mouse. Event me) • Mouse. Motion. Listener • void mouse. Dragged (Mouse. Event me) • void mouse. Moved (Mouse. Event me) //pressed or released on a component //no buttons have been pushed • Text. Listener • void text. Value. Changed (Text. Event te) • Window. Listener • void window. Activated (Window. Event we) • void window. Closing (Window. Event we) • void window. Deactivated (Window. Event we) • void window. Deiconified (Window. Event we) //from a minimized to a normal state • void window. Iconified (Window. Event we) //from a normal to a minimized state • void window. Opened (Window. Event we)
GOOD LUCK ! ☻. . .
- Slides: 11