SlideShare ist ein Scribd-Unternehmen logo
1 von 30
PROGRAMMING IN JAVA
A. SIVASANKARI
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATION
SHANMUGA INDUSTRIES ARTS AND SCIENCE
COLLEGE,
TIRUVANNAMALAI. 606601.
Email: sivasankaridkm@gmail.com
PROGRAMMING IN JAVA
UNIT - 4
PART II
 AWT EVENT HANDLING
 AWT EVENT CLASSES
 AWT EVENT LISTENERS
 AWT ADAPTER CLASSES
 AWT CONTAINERS
 AWT LAYOUT MANAGER
 AWT MENU CLASSES
 MENU CONTROLS
 AWT GRAPHICS CLASSES
 GRAPHICS
 WINDOW FUNDAMENTALS
 WORKING WITH FRAME WINDOW
 WORKING WITH GRAPHICS
A. SIVASANKARI - SIASC-TVM UNIT-4
PROGRAMMING IN JAVA
AWT EVENT HANDLING
EVENT
• Change in the state of an object is known as event i.e. event describes the change in state of
source. Events are generated as result of user interaction with the graphical user interface
components. For example, clicking on a button, moving the mouse, entering a character
through keyboard, selecting an item from list, scrolling the page are the activities that causes
an event to happen.
TYPES OF EVENT
• The events can be broadly classified into two categories:
• Foreground Events - Those events which require the direct interaction of user. They are
generated as consequences of a person interacting with the graphical components in Graphical
User Interface. For example, clicking on a button, moving the mouse, entering a character
through keyboard, selecting an item from list, scrolling the page etc.
• Background Events - Those events that require the interaction of end user are known as
background events. Operating system interrupts, hardware or software failure, timer expires,
an operation completion are the example of background events.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
EVENT HANDLING
• Event Handling is the mechanism that controls the event and decides what should happen if
an event occurs. This mechanism have the code which is known as event handler that is
executed when an event occurs. Java Uses the Delegation Event Model to handle the events.
This model defines the standard mechanism to generate and handle the events.
• The Delegation Event Model has the following key participants namely:
• Source - The source is an object on which event occurs. Source is responsible for providing
information of the occurred event to it's handler. Java provide as with classes for source
object.
• Listener - It is also known as event handler. Listener is responsible for generating response to
an event. From java implementation point of view the listener is also an object. Listener waits
until it receives an event. Once the event is received , the listener process the event an then
returns.
• The benefit of this approach is that the user interface logic is completely separated from the
logic that generates the event. The user interface element is able to delegate the processing
of an event to the separate piece of code. In this model ,Listener needs to be registered with
the source object so that the listener can receive the event notification. This is an efficient way
of handling the event because the event notifications are sent only to those listener that want
to receive them.
STEPS INVOLVED IN EVENT HANDLING
• The User clicks the button and the event is generated.
• Now the object of concerned event class is created automatically and information about the
source and the event get populated with in same object.
• Event object is forwarded to the method of registered listener class.
• The method is now get executed and returns.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT EVENTS
• Java.awt.event.*;
EVENT CLASSES
Syntax:
• Event object(object src)
It contains two methods.
1. getsource( ) returns source of the event 2.tostring( ) returns the string equivalent of the
event.
Events Commands
Action event Button press or double clicked.
Adjustment event Scrollbar is manipulated.
Component event Hidden, resized, moved etc
Container event Component is added or removed.
Focus event Keyboard focus
Input event All input component
Item event Checkbox or listed items
Key event Keyboard process
Mouse event Mouse process
Text event Text area or text field
Window event Window close, open or quit.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
ACTION EVENT
• Syntax:
• ActionEvent(object src, int type, String cmd)
• Example:
• String getactionCommand( )
• Int getmodifiers( )
ADJUSTMENT EVENT
• Syntax:
• Adjustable getadjustable( )
• Example:
• int getadjusttype( )
• int getvalue( )
COMPONENT EVENT
• Syntax:
• ComponentEvent( component src, int type)
• Example:
• Component getcomponent( )
• Constants are:
• COMPONENT-HIDDEN
• COMPONENT-MOVED
• COMPONENT-RESIZED
• COMPONENT-SHOWN
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
CONTAINER EVENT
• Syntax:
• ContainerEvent( component src, int type, component comp)
• Example:
• Component getchild( );
• Container getContainer( );
FOCUS EVENT
• The constants are:
• FOCUS-GAINED
• FOCUS-LOST
• Syntax:
• FocusEvent(component src, int type,..)
• Example:
• Component getOppositeComponent( )
• Boolean Istemporary( )
INPUT EVENT
• Key event
• Mouse event
• The constants are
• Ctrl-mask, shift-mask, alt-mask,…
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• Syntax:
• Boolean is Altdown( )
• Boolean is AltGraphdown( )
• Example:
• int getmodifiers( );
ITEM EVENT:
• The constants are
• Deselected
• Selected
• Syntax:
• ItemEvent( itemSelectable src, int type, obj entry)
• Example:
• Object getItem( );
KEY EVENT:
• Digits: VK _ 0 TO VK_ 9
• Character: VK _ A to VK _ Z, VK _ ENTER, VK_ UP .. etc
• Syntax:
• KeyEvent(component src, int type, long when, int modifiers, int code, char ch);
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
Example:
• Char getkeychar( );
• Int getkeycode ( );
MOUSE EVENT
• Constants are :
• MOUSE-CLICKED, MOUSE- ENTERED, MOUSE-DRAGGED, MOUSE-EXITED,
MOUSE-MOVED, MOUSE-PRESSED, MOUSE-RELEASED, MOUSE-WHEEL.
• Syntax:
• MouseEvent(Component src, int type, long when,
• int modifiers, int x, int y, int clicks, Boolean trigger )
Example:
• int getclickcount( );
• int getButton( );
MOUSE WHEEL EVENT
• Constants are:
• WHEEL-BLOCK-SCROLL
• WHEEL-UNIT-SCROLL
• Syntax:
• MouseWheelEvent(Component src, int type, long when, int Modifiers, int x, int y, int clicks,
• Boolean trigger, int amount,int scroll, int count)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
• Example:
• int getWheelRotation( )
• int getscrolltype( )
TEXT EVENT
• Constants are
• TEXT-VALUE-CHANGED
• Syntax:
• TextEvent(object src, int type)
WINDOW EVENT
• Constants are
• WINDOW-ACTIVATED, CLOSED, CLOSING,
• DEACTIVATED, LOST FOCUS, OPENED,…
• Syntax:
• WindowEvent(window src, int type)
• Example:
• int getAppositeWindow( )
• int getOldState ( )
SOURCE OF EVENTS
• Src-Button, checkbox, choice, list, menu item,
• scroll bar, text, window.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT EVENT LISTENERS
• The Event listener represent the interfaces responsible to handle events. Java provides us
various Event listener classes but we will discuss those which are more frequently used. Every
method of an event listener method has a single argument as an object which is subclass of
EventObject class. For example, mouse event listener methods will accept instance of
MouseEvent, where MouseEvent derives from EventObject.
EventListner interface
• It is a marker interface which every listener interface has to extend. This class is defined in
java.util package.
• Java .awt.event.packages
Class declaration
• Following is the declaration for java.util.EventListener interface:
• public interface EventListener
• AWT Event Listener Interfaces:
Following is the list of commonly used event listeners.
ACTION LISTENER INTERFACES
• Example:
• void ActionPerformed(ActionEvent ae)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
COMPONENT LISTENER INTERFACE
• Example:
• void ComponentResized( ComponentEvent ce)
• void ComponentMoved( ComponentEvent ce)
• void ComponentShown( ComponentEvent ce)
• void ComponentHidden( ComponentEvent ce)
CONTAINER LISTENER INTERFACE
• Example:
• void ContainerAdded(ContainerEvent ce)
• void ContainerRemoveed(ContainerEvent ce)
FOCUS LISTENER INTERFACE
• Example:
• void FocusGained(FocusEvent fe)
• void FocusLost(FocusEvent fe)
ITEM LISTENER INTERFACE
• Example:
• void ItemStateChanged(ItemEvent ie)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
KEY LISTENER INTERFACE
• Example:
• void KeyPressed(KeyEvent ke)
• void KeyReleased(KeyEvent ke)
• void KeyTyped(KeyEvent ke)
MOUSE LISTENER INTERFACE
• Example:
• void MouseClicked(MouseEvent me)
• void MouseEntered(MouseEvent me)
• void MousePressed(MouseEvent me)
MOUSE MOTION LISTENER INTERFACE
• Example:
• void MouseDragged(MouseMotionEvent mme)
• void MouseMoved(MouseMotionEvent mme)
MOUSE WHEEL LISTENER INTERFACE
• Example:
• void MouseWheelMoved(MouseWheelEvent mwe)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
TEXT LISTENER INTERFACE
• Example:
• void TextChanged(TextEvent te)
WINDOW LISTENER INTERFACE
• Example:
• void WindowActivated(WindowEvent we)
ADAPTER CLASS LISTENER INTERFACE
ComponentAdapter ComponentListener
ContainerAdapter ContainerListener
FocusAdapter FocusListener
KeyAdapter KeyListener
MouseAdapter MouseListener
MouseMotionAdapter MouseMotionListener
WindowAdapter WindowListener
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT ADAPTER CLASSES
• An adapter class provides an empty implementation of all methods in an event listener interface. It
execute or want particular events
• Adapters are abstract classes for receiving various events. The methods in these classes are empty.
These classes exists as convenience for creating listener objects.
AWT Adapters
• Following is the list of commonly used adapters while listening GUI events in AWT.
Sr. No. Adapter & Description
1 FocusAdapter An abstract adapter class for receiving focus events.
2 KeyAdapter An abstract adapter class for receiving key events.
3 MouseAdapter An abstract adapter class for receiving mouse events.
4 MouseMotionAdapter An abstract adapter class for receiving mouse motion events.
5 WindowAdapter An abstract adapter class for receiving window events.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT CONTAINERS
• Containers are integral part of AWT GUI components. A container provides a space where a
component can be located. A Container in AWT is a component itself and it adds the
capability to add component to itself. Following are noticeable points to be considered.
• Sub classes of Container are called as Containter. For example Panel, Frame and Window.
• Container can add only Component to itself.
• A default layout is present in each container which can be overridden using setLayout method.
AWT UI ELEMENTS
• Following is the list of commonly used containers while designed GUI using AWT.
S No. AWT Container & Description
1 Container It is a generic container object which can contain other AWT components.
S No AWT UI Container & Description
1 Panel Panel is the simplest container. It provides space in which any other component can be
placed, including other panels.
2 Frame A Frame is a top-level window with a title and a border
3 Window A Window object is a top-level window with no borders and no menubar.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
LAYOUT MANAGER
LAYOUT
• Layout means the arrangement of components within the container. In other way
we can say that placing the components at a particular position within the container.
The task of layouting the controls is done automatically by the Layout Manager.
LAYOUT MANAGER
• The layout manager automatically positions all the components within the
container. If we do not use layout manager then also the components are positioned
by the default layout manager. It is possible to layout the controls by hand but it
becomes very difficult because of the following two reasons.
• It is very tedious to handle a large number of controls within the container.
• Oftenly the width and height information of a component is not given when we
need to arrange them.
• Java provide us with various layout manager to position the controls. The properties
like size, shape and arrangement varies from one layout manager to other layout
manager. When the size of the applet or the application window changes the size,
shape and arrangement of the components also changes in response i.e. the layout
managers adapt to the dimensions of appletviewer or the application window.
• The layout manager is associated with every Container object.
• Each layout manager is an object of the class that implements the LayoutManager
interface.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
LAYOUT MARQUES
• Each container object as a layout manager associated with it.
• It is otherwise called as Layout Managers.
Syntax
• void SetLayout(LayoutManage layobject)
TYPES OF LAYOUT
S No. LayoutManager & Description
1 BorderLayout The borderlayout arranges the components to fit in the five regions: east,
west, north, south and center.
2 CardLayoutT he CardLayout object treats each component in the container as a card. Only
one card is visible at a time.
3 FlowLayout The FlowLayout is the default layout.It layouts the components in a directional
flow.
4 GridLayout The GridLayout manages the components in form of a rectangular grid.
5 GridBagLayout This is the most flexible layout manager class.The object of GridBagLayout
aligns the component vertically,horizontally or along their baseline without requiring the
components of same size.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
FLOW LAYOUT
• Syntax:
• FlowLayout( )
• Example:
• FlowLayout.LEFT
• FlowLayout.RIGHT
• FlowLayout.CENTER
BORDER LAYOUT
• Syntax:
• BorderLayout( )
• Example:
• BorderLayout.CENTER
• BorderLayout.EAST
• BorderLayout.WEST
• BorderLayout.SOUTH
• BorderLayout.NORTH
GRID LAYOUT
• Syntax:
• GridLayout( )
• Example:
• Calculator
• Personal Resume
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT MENU CLASSES
• As we know that every top-level window has a menu bar associated with it. This menu bar
consist of various menu choices available to the end user. Further each choice contains list of
options which is called drop down menus. Menu and MenuItem controls are subclass of
MenuComponent class.
MENU HIERARCHY
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
MENU CONTROLS
S.
No.
Menu Controls & Description
1 MenuComponent It is the top level class for all menu related controls.
2 MenuBar The MenuBar object is associated with the top-level window.
3 MenuItem The items in the menu must belong to the MenuItem or any of its subclass.
4 Menu The Menu object is a pull-down menu component which is displayed from the menu
bar.
5 CheckboxMenuItem CheckboxMenuItem is subclass of MenuItem.
6 PopupMenu PopupMenu can be dynamically popped up at a specified position within a
component.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
AWT GRAPHICS CLASSES
• Graphics controls allows application to draw onto the component or on image.
GRAPHICS CONTROLS
SNo. Control & Description
1 Graphics It is the top level abstract class for all graphics contexts.
2 Graphics2D It is a subclass of Graphics class and provides more sophisticated control over
geometry, coordinate transformations, color management, and text layout.
3 Arc2D Arc2D is the abstract superclass for all objects that store a 2D arc defined by a framing
rectangle, start angle, angular extent (length of the arc), and a closure type (OPEN, CHORD,
or PIE).
4 CubicCurve2D The CubicCurve2D class is the abstract superclass fpr all objects which store a
2D cubic curve segment and it defines a cubic parametric curve segment in (x,y) coordinate
space.
5 Ellipse2D The Ellipse2D is the abstract superclass for all objects which store a 2D ellipse and
it describes an ellipse that is defined by a framing rectangle.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
Sr.
No.
Control & Description
6 Rectangle2D The Rectangle2D class is an abstract superclass for all objects that store a 2D
rectangle and it describes a rectangle defined by a location (x,y) and dimension (w x h).
7 QuadCurve2D The QuadCurve2D class is an abstract superclass for all objects that store a 2D
quadratic curve segment and it describes a quadratic parametric curve segment in (x,y)
coordinate space.
8 Line2D This Line2D represents a line segment in (x,y) coordinate space.
9 Font The Font class represents fonts, which are used to render text in a visible way.
10 Color The Color class is used encapsulate colors in the default sRGB color space or colors in
arbitrary color spaces identified by a ColorSpace.
11 BasicStroke The BasicStroke class defines a basic set of rendering attributes for the outlines of
graphics primitives, which are rendered with a Graphics2D object that has its Stroke attribute set
to this BasicStroke.
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
GRAPHICS
WINDOW FUNDAMENTALS
1. COMPONENTS
• It is an abstract class that encapsulate all of the attributes of a visual components
• A components object is responsible for remembering the current foreground and
background colors and the currently selected text font.
2. CONTAINER
• The container class is a subclass of components
• A container is responsible for laying out any components that is contains.
3. PANEL
• It is a subclass of container
• It is a superclass for applet
• Panel is a window that does not contain a title bar, Menubar or border.
The methods are SetLocation(),setsize(), or setbounds()
4.WINDOW
• It is called window
5.FRAME
• It is a subclass of window and has a tittlebar, menubar,border and resizing corners
6.CANVAS
• Canvas encapsulate a blank window upon which we can draw
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
WORKING WITH FRAME WINDOW
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
FRAME
• Sytanx:
• Frame()
• Frame(string title)
Size setting
• Sytanx:
• Void SetSize( Int new width.int new height)
• Void SetSize( Dimension new size)
Hidding and Showing a Window
• Sytanx:
• Void Setvisible ( Boolean visible flag )
• // True Means Visible // False Hidden
Setting a window title
• Sytanx:
• Void settittle(string new title)
Closing a Frame
• Sytanx :
• Set visible(False) or Window Closing()
• Example
• Panel and Layout. Record
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
WORKING WITH GRAPHICS
• The origin of each window is at the topleft corner and is 0.0.
• Coordinates are specified in Pixels use two ways.
• Paint() or update()
• getgraphics()
DRAWING LINES
• Syntax:
• Void drawline (int starting,int stray,int stray,int endx,int endy)
• Ex:
• g.drawline(0, 0, 100, 100)
• g.drawline(0, 100, 100 ,0)
DRAWING RECTANGLE
• Syntax:
• Void drawrect(int top, int left, int width, int height)
• Void fillrect(int top, int left, int width, int height)
ROUNDED RECTANGLE
• Syntax:
Void drawroundrect(int top, int left, int width,
int height, int xdim, int ydim)
• Example:
• g.drawrect(10, 10,60, 50)
• g.fillroundrect(70,90, 140.100,30,40,)
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
DRAWING ELLIPSES AND CIRCLE
• Syntax:
• Void drawOval(int top, int left, int width, int height)
• Void filloval(int top, int left, int width, int height)
• Example :
• g. drawoval(10,10,50,50)
• g.filloval(100,10,75,50)
DRAWING ARCS
• Syntax:
• Void drawarc(int top, int left, int width, int height, int startangle, int sweepangle);
• Void fillarc(int top, int left, int width, int height, int startangle, int sweepangle);
DRAWING POLYGONS
• Syntax:
• Void drawPolygon(int [],int, [], int num of points);
• Void fillPolygon(int [],int, [], int num of points);
WORKING WITH COLORS
• Syntax:
• Setcolor();
• New color(255,100,100);
Two type of colors:
• 1.HSB - Hue, Satuaration, Brightness
• 2. RGB – Red, Green, Blue
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
Example:
• Get red();
• int getgreen();
• int getblue();
• int getrgb();
WORKING WITH FONTS
• Fonts have a family name, logical name and face name.
• Family namily General name of font
• Example: Courier
• Logical name Category of font
• Example: monospaced
• Face name Specific font
• Example: Courier italic
• Syntax are methods :
• String getfamily(); String getname(); Int get style();
• Boolean is Bold();
• Syntax: Font(String font name, int fontstyle, int pointsize)
• Ex: Void setfont(font fontobject)
A. SIVASANKARI - SIASC-TVM
A. SIVASANKARI - SIASC-TVM

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced java
Advanced java Advanced java
Advanced java
NA
 

Was ist angesagt? (18)

basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Advanced java
Advanced java Advanced java
Advanced java
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java basics
Java basicsJava basics
Java basics
 
Core java introduction
Core java introductionCore java introduction
Core java introduction
 
Core Java
Core JavaCore Java
Core Java
 
Domino java
Domino javaDomino java
Domino java
 
Java Certification Tutorial | Java Tutorial For Beginners | Java Training | E...
Java Certification Tutorial | Java Tutorial For Beginners | Java Training | E...Java Certification Tutorial | Java Tutorial For Beginners | Java Training | E...
Java Certification Tutorial | Java Tutorial For Beginners | Java Training | E...
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...
 

Ähnlich wie PROGRAMMING IN JAVA- unit 4-part II

ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 

Ähnlich wie PROGRAMMING IN JAVA- unit 4-part II (20)

JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Events1
Events1Events1
Events1
 
Awt event
Awt eventAwt event
Awt event
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
File Handling
File HandlingFile Handling
File Handling
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
09events
09events09events
09events
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
 
AWTEventModel
AWTEventModelAWTEventModel
AWTEventModel
 
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
CS3391 -OOP -UNIT – V NOTES FINAL.pdfCS3391 -OOP -UNIT – V NOTES FINAL.pdf
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
 
7java Events
7java Events7java Events
7java Events
 
Event handling
Event handlingEvent handling
Event handling
 
Oracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxOracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptx
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 

Mehr von SivaSankari36

MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
SivaSankari36
 

Mehr von SivaSankari36 (6)

DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARI
 
CLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARICLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARI
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
 
MOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARIMOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARI
 
Functional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationFunctional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data Application
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

PROGRAMMING IN JAVA- unit 4-part II

  • 1. PROGRAMMING IN JAVA A. SIVASANKARI ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATION SHANMUGA INDUSTRIES ARTS AND SCIENCE COLLEGE, TIRUVANNAMALAI. 606601. Email: sivasankaridkm@gmail.com
  • 2. PROGRAMMING IN JAVA UNIT - 4 PART II  AWT EVENT HANDLING  AWT EVENT CLASSES  AWT EVENT LISTENERS  AWT ADAPTER CLASSES  AWT CONTAINERS  AWT LAYOUT MANAGER  AWT MENU CLASSES  MENU CONTROLS  AWT GRAPHICS CLASSES  GRAPHICS  WINDOW FUNDAMENTALS  WORKING WITH FRAME WINDOW  WORKING WITH GRAPHICS A. SIVASANKARI - SIASC-TVM UNIT-4
  • 3. PROGRAMMING IN JAVA AWT EVENT HANDLING EVENT • Change in the state of an object is known as event i.e. event describes the change in state of source. Events are generated as result of user interaction with the graphical user interface components. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen. TYPES OF EVENT • The events can be broadly classified into two categories: • Foreground Events - Those events which require the direct interaction of user. They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page etc. • Background Events - Those events that require the interaction of end user are known as background events. Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events. A. SIVASANKARI - SIASC-TVM
  • 4. PROGRAMMING IN JAVA EVENT HANDLING • Event Handling is the mechanism that controls the event and decides what should happen if an event occurs. This mechanism have the code which is known as event handler that is executed when an event occurs. Java Uses the Delegation Event Model to handle the events. This model defines the standard mechanism to generate and handle the events. • The Delegation Event Model has the following key participants namely: • Source - The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler. Java provide as with classes for source object. • Listener - It is also known as event handler. Listener is responsible for generating response to an event. From java implementation point of view the listener is also an object. Listener waits until it receives an event. Once the event is received , the listener process the event an then returns. • The benefit of this approach is that the user interface logic is completely separated from the logic that generates the event. The user interface element is able to delegate the processing of an event to the separate piece of code. In this model ,Listener needs to be registered with the source object so that the listener can receive the event notification. This is an efficient way of handling the event because the event notifications are sent only to those listener that want to receive them. STEPS INVOLVED IN EVENT HANDLING • The User clicks the button and the event is generated. • Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object. • Event object is forwarded to the method of registered listener class. • The method is now get executed and returns. A. SIVASANKARI - SIASC-TVM
  • 5. PROGRAMMING IN JAVA AWT EVENTS • Java.awt.event.*; EVENT CLASSES Syntax: • Event object(object src) It contains two methods. 1. getsource( ) returns source of the event 2.tostring( ) returns the string equivalent of the event. Events Commands Action event Button press or double clicked. Adjustment event Scrollbar is manipulated. Component event Hidden, resized, moved etc Container event Component is added or removed. Focus event Keyboard focus Input event All input component Item event Checkbox or listed items Key event Keyboard process Mouse event Mouse process Text event Text area or text field Window event Window close, open or quit. A. SIVASANKARI - SIASC-TVM
  • 6. PROGRAMMING IN JAVA ACTION EVENT • Syntax: • ActionEvent(object src, int type, String cmd) • Example: • String getactionCommand( ) • Int getmodifiers( ) ADJUSTMENT EVENT • Syntax: • Adjustable getadjustable( ) • Example: • int getadjusttype( ) • int getvalue( ) COMPONENT EVENT • Syntax: • ComponentEvent( component src, int type) • Example: • Component getcomponent( ) • Constants are: • COMPONENT-HIDDEN • COMPONENT-MOVED • COMPONENT-RESIZED • COMPONENT-SHOWN A. SIVASANKARI - SIASC-TVM
  • 7. PROGRAMMING IN JAVA CONTAINER EVENT • Syntax: • ContainerEvent( component src, int type, component comp) • Example: • Component getchild( ); • Container getContainer( ); FOCUS EVENT • The constants are: • FOCUS-GAINED • FOCUS-LOST • Syntax: • FocusEvent(component src, int type,..) • Example: • Component getOppositeComponent( ) • Boolean Istemporary( ) INPUT EVENT • Key event • Mouse event • The constants are • Ctrl-mask, shift-mask, alt-mask,… A. SIVASANKARI - SIASC-TVM
  • 8. PROGRAMMING IN JAVA • Syntax: • Boolean is Altdown( ) • Boolean is AltGraphdown( ) • Example: • int getmodifiers( ); ITEM EVENT: • The constants are • Deselected • Selected • Syntax: • ItemEvent( itemSelectable src, int type, obj entry) • Example: • Object getItem( ); KEY EVENT: • Digits: VK _ 0 TO VK_ 9 • Character: VK _ A to VK _ Z, VK _ ENTER, VK_ UP .. etc • Syntax: • KeyEvent(component src, int type, long when, int modifiers, int code, char ch); A. SIVASANKARI - SIASC-TVM
  • 9. PROGRAMMING IN JAVA Example: • Char getkeychar( ); • Int getkeycode ( ); MOUSE EVENT • Constants are : • MOUSE-CLICKED, MOUSE- ENTERED, MOUSE-DRAGGED, MOUSE-EXITED, MOUSE-MOVED, MOUSE-PRESSED, MOUSE-RELEASED, MOUSE-WHEEL. • Syntax: • MouseEvent(Component src, int type, long when, • int modifiers, int x, int y, int clicks, Boolean trigger ) Example: • int getclickcount( ); • int getButton( ); MOUSE WHEEL EVENT • Constants are: • WHEEL-BLOCK-SCROLL • WHEEL-UNIT-SCROLL • Syntax: • MouseWheelEvent(Component src, int type, long when, int Modifiers, int x, int y, int clicks, • Boolean trigger, int amount,int scroll, int count) A. SIVASANKARI - SIASC-TVM
  • 10. PROGRAMMING IN JAVA • Example: • int getWheelRotation( ) • int getscrolltype( ) TEXT EVENT • Constants are • TEXT-VALUE-CHANGED • Syntax: • TextEvent(object src, int type) WINDOW EVENT • Constants are • WINDOW-ACTIVATED, CLOSED, CLOSING, • DEACTIVATED, LOST FOCUS, OPENED,… • Syntax: • WindowEvent(window src, int type) • Example: • int getAppositeWindow( ) • int getOldState ( ) SOURCE OF EVENTS • Src-Button, checkbox, choice, list, menu item, • scroll bar, text, window. A. SIVASANKARI - SIASC-TVM
  • 11. PROGRAMMING IN JAVA AWT EVENT LISTENERS • The Event listener represent the interfaces responsible to handle events. Java provides us various Event listener classes but we will discuss those which are more frequently used. Every method of an event listener method has a single argument as an object which is subclass of EventObject class. For example, mouse event listener methods will accept instance of MouseEvent, where MouseEvent derives from EventObject. EventListner interface • It is a marker interface which every listener interface has to extend. This class is defined in java.util package. • Java .awt.event.packages Class declaration • Following is the declaration for java.util.EventListener interface: • public interface EventListener • AWT Event Listener Interfaces: Following is the list of commonly used event listeners. ACTION LISTENER INTERFACES • Example: • void ActionPerformed(ActionEvent ae) A. SIVASANKARI - SIASC-TVM
  • 12. PROGRAMMING IN JAVA COMPONENT LISTENER INTERFACE • Example: • void ComponentResized( ComponentEvent ce) • void ComponentMoved( ComponentEvent ce) • void ComponentShown( ComponentEvent ce) • void ComponentHidden( ComponentEvent ce) CONTAINER LISTENER INTERFACE • Example: • void ContainerAdded(ContainerEvent ce) • void ContainerRemoveed(ContainerEvent ce) FOCUS LISTENER INTERFACE • Example: • void FocusGained(FocusEvent fe) • void FocusLost(FocusEvent fe) ITEM LISTENER INTERFACE • Example: • void ItemStateChanged(ItemEvent ie) A. SIVASANKARI - SIASC-TVM
  • 13. PROGRAMMING IN JAVA KEY LISTENER INTERFACE • Example: • void KeyPressed(KeyEvent ke) • void KeyReleased(KeyEvent ke) • void KeyTyped(KeyEvent ke) MOUSE LISTENER INTERFACE • Example: • void MouseClicked(MouseEvent me) • void MouseEntered(MouseEvent me) • void MousePressed(MouseEvent me) MOUSE MOTION LISTENER INTERFACE • Example: • void MouseDragged(MouseMotionEvent mme) • void MouseMoved(MouseMotionEvent mme) MOUSE WHEEL LISTENER INTERFACE • Example: • void MouseWheelMoved(MouseWheelEvent mwe) A. SIVASANKARI - SIASC-TVM
  • 14. PROGRAMMING IN JAVA TEXT LISTENER INTERFACE • Example: • void TextChanged(TextEvent te) WINDOW LISTENER INTERFACE • Example: • void WindowActivated(WindowEvent we) ADAPTER CLASS LISTENER INTERFACE ComponentAdapter ComponentListener ContainerAdapter ContainerListener FocusAdapter FocusListener KeyAdapter KeyListener MouseAdapter MouseListener MouseMotionAdapter MouseMotionListener WindowAdapter WindowListener A. SIVASANKARI - SIASC-TVM
  • 15. PROGRAMMING IN JAVA AWT ADAPTER CLASSES • An adapter class provides an empty implementation of all methods in an event listener interface. It execute or want particular events • Adapters are abstract classes for receiving various events. The methods in these classes are empty. These classes exists as convenience for creating listener objects. AWT Adapters • Following is the list of commonly used adapters while listening GUI events in AWT. Sr. No. Adapter & Description 1 FocusAdapter An abstract adapter class for receiving focus events. 2 KeyAdapter An abstract adapter class for receiving key events. 3 MouseAdapter An abstract adapter class for receiving mouse events. 4 MouseMotionAdapter An abstract adapter class for receiving mouse motion events. 5 WindowAdapter An abstract adapter class for receiving window events. A. SIVASANKARI - SIASC-TVM
  • 16. PROGRAMMING IN JAVA AWT CONTAINERS • Containers are integral part of AWT GUI components. A container provides a space where a component can be located. A Container in AWT is a component itself and it adds the capability to add component to itself. Following are noticeable points to be considered. • Sub classes of Container are called as Containter. For example Panel, Frame and Window. • Container can add only Component to itself. • A default layout is present in each container which can be overridden using setLayout method. AWT UI ELEMENTS • Following is the list of commonly used containers while designed GUI using AWT. S No. AWT Container & Description 1 Container It is a generic container object which can contain other AWT components. S No AWT UI Container & Description 1 Panel Panel is the simplest container. It provides space in which any other component can be placed, including other panels. 2 Frame A Frame is a top-level window with a title and a border 3 Window A Window object is a top-level window with no borders and no menubar. A. SIVASANKARI - SIASC-TVM
  • 17. PROGRAMMING IN JAVA LAYOUT MANAGER LAYOUT • Layout means the arrangement of components within the container. In other way we can say that placing the components at a particular position within the container. The task of layouting the controls is done automatically by the Layout Manager. LAYOUT MANAGER • The layout manager automatically positions all the components within the container. If we do not use layout manager then also the components are positioned by the default layout manager. It is possible to layout the controls by hand but it becomes very difficult because of the following two reasons. • It is very tedious to handle a large number of controls within the container. • Oftenly the width and height information of a component is not given when we need to arrange them. • Java provide us with various layout manager to position the controls. The properties like size, shape and arrangement varies from one layout manager to other layout manager. When the size of the applet or the application window changes the size, shape and arrangement of the components also changes in response i.e. the layout managers adapt to the dimensions of appletviewer or the application window. • The layout manager is associated with every Container object. • Each layout manager is an object of the class that implements the LayoutManager interface. A. SIVASANKARI - SIASC-TVM
  • 18. PROGRAMMING IN JAVA LAYOUT MARQUES • Each container object as a layout manager associated with it. • It is otherwise called as Layout Managers. Syntax • void SetLayout(LayoutManage layobject) TYPES OF LAYOUT S No. LayoutManager & Description 1 BorderLayout The borderlayout arranges the components to fit in the five regions: east, west, north, south and center. 2 CardLayoutT he CardLayout object treats each component in the container as a card. Only one card is visible at a time. 3 FlowLayout The FlowLayout is the default layout.It layouts the components in a directional flow. 4 GridLayout The GridLayout manages the components in form of a rectangular grid. 5 GridBagLayout This is the most flexible layout manager class.The object of GridBagLayout aligns the component vertically,horizontally or along their baseline without requiring the components of same size. A. SIVASANKARI - SIASC-TVM
  • 19. PROGRAMMING IN JAVA FLOW LAYOUT • Syntax: • FlowLayout( ) • Example: • FlowLayout.LEFT • FlowLayout.RIGHT • FlowLayout.CENTER BORDER LAYOUT • Syntax: • BorderLayout( ) • Example: • BorderLayout.CENTER • BorderLayout.EAST • BorderLayout.WEST • BorderLayout.SOUTH • BorderLayout.NORTH GRID LAYOUT • Syntax: • GridLayout( ) • Example: • Calculator • Personal Resume A. SIVASANKARI - SIASC-TVM
  • 20. PROGRAMMING IN JAVA AWT MENU CLASSES • As we know that every top-level window has a menu bar associated with it. This menu bar consist of various menu choices available to the end user. Further each choice contains list of options which is called drop down menus. Menu and MenuItem controls are subclass of MenuComponent class. MENU HIERARCHY A. SIVASANKARI - SIASC-TVM
  • 21. PROGRAMMING IN JAVA MENU CONTROLS S. No. Menu Controls & Description 1 MenuComponent It is the top level class for all menu related controls. 2 MenuBar The MenuBar object is associated with the top-level window. 3 MenuItem The items in the menu must belong to the MenuItem or any of its subclass. 4 Menu The Menu object is a pull-down menu component which is displayed from the menu bar. 5 CheckboxMenuItem CheckboxMenuItem is subclass of MenuItem. 6 PopupMenu PopupMenu can be dynamically popped up at a specified position within a component. A. SIVASANKARI - SIASC-TVM
  • 22. PROGRAMMING IN JAVA AWT GRAPHICS CLASSES • Graphics controls allows application to draw onto the component or on image. GRAPHICS CONTROLS SNo. Control & Description 1 Graphics It is the top level abstract class for all graphics contexts. 2 Graphics2D It is a subclass of Graphics class and provides more sophisticated control over geometry, coordinate transformations, color management, and text layout. 3 Arc2D Arc2D is the abstract superclass for all objects that store a 2D arc defined by a framing rectangle, start angle, angular extent (length of the arc), and a closure type (OPEN, CHORD, or PIE). 4 CubicCurve2D The CubicCurve2D class is the abstract superclass fpr all objects which store a 2D cubic curve segment and it defines a cubic parametric curve segment in (x,y) coordinate space. 5 Ellipse2D The Ellipse2D is the abstract superclass for all objects which store a 2D ellipse and it describes an ellipse that is defined by a framing rectangle. A. SIVASANKARI - SIASC-TVM
  • 23. PROGRAMMING IN JAVA Sr. No. Control & Description 6 Rectangle2D The Rectangle2D class is an abstract superclass for all objects that store a 2D rectangle and it describes a rectangle defined by a location (x,y) and dimension (w x h). 7 QuadCurve2D The QuadCurve2D class is an abstract superclass for all objects that store a 2D quadratic curve segment and it describes a quadratic parametric curve segment in (x,y) coordinate space. 8 Line2D This Line2D represents a line segment in (x,y) coordinate space. 9 Font The Font class represents fonts, which are used to render text in a visible way. 10 Color The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace. 11 BasicStroke The BasicStroke class defines a basic set of rendering attributes for the outlines of graphics primitives, which are rendered with a Graphics2D object that has its Stroke attribute set to this BasicStroke. A. SIVASANKARI - SIASC-TVM
  • 24. PROGRAMMING IN JAVA GRAPHICS WINDOW FUNDAMENTALS 1. COMPONENTS • It is an abstract class that encapsulate all of the attributes of a visual components • A components object is responsible for remembering the current foreground and background colors and the currently selected text font. 2. CONTAINER • The container class is a subclass of components • A container is responsible for laying out any components that is contains. 3. PANEL • It is a subclass of container • It is a superclass for applet • Panel is a window that does not contain a title bar, Menubar or border. The methods are SetLocation(),setsize(), or setbounds() 4.WINDOW • It is called window 5.FRAME • It is a subclass of window and has a tittlebar, menubar,border and resizing corners 6.CANVAS • Canvas encapsulate a blank window upon which we can draw A. SIVASANKARI - SIASC-TVM
  • 25. PROGRAMMING IN JAVA WORKING WITH FRAME WINDOW A. SIVASANKARI - SIASC-TVM
  • 26. PROGRAMMING IN JAVA FRAME • Sytanx: • Frame() • Frame(string title) Size setting • Sytanx: • Void SetSize( Int new width.int new height) • Void SetSize( Dimension new size) Hidding and Showing a Window • Sytanx: • Void Setvisible ( Boolean visible flag ) • // True Means Visible // False Hidden Setting a window title • Sytanx: • Void settittle(string new title) Closing a Frame • Sytanx : • Set visible(False) or Window Closing() • Example • Panel and Layout. Record A. SIVASANKARI - SIASC-TVM
  • 27. PROGRAMMING IN JAVA WORKING WITH GRAPHICS • The origin of each window is at the topleft corner and is 0.0. • Coordinates are specified in Pixels use two ways. • Paint() or update() • getgraphics() DRAWING LINES • Syntax: • Void drawline (int starting,int stray,int stray,int endx,int endy) • Ex: • g.drawline(0, 0, 100, 100) • g.drawline(0, 100, 100 ,0) DRAWING RECTANGLE • Syntax: • Void drawrect(int top, int left, int width, int height) • Void fillrect(int top, int left, int width, int height) ROUNDED RECTANGLE • Syntax: Void drawroundrect(int top, int left, int width, int height, int xdim, int ydim) • Example: • g.drawrect(10, 10,60, 50) • g.fillroundrect(70,90, 140.100,30,40,) A. SIVASANKARI - SIASC-TVM
  • 28. PROGRAMMING IN JAVA DRAWING ELLIPSES AND CIRCLE • Syntax: • Void drawOval(int top, int left, int width, int height) • Void filloval(int top, int left, int width, int height) • Example : • g. drawoval(10,10,50,50) • g.filloval(100,10,75,50) DRAWING ARCS • Syntax: • Void drawarc(int top, int left, int width, int height, int startangle, int sweepangle); • Void fillarc(int top, int left, int width, int height, int startangle, int sweepangle); DRAWING POLYGONS • Syntax: • Void drawPolygon(int [],int, [], int num of points); • Void fillPolygon(int [],int, [], int num of points); WORKING WITH COLORS • Syntax: • Setcolor(); • New color(255,100,100); Two type of colors: • 1.HSB - Hue, Satuaration, Brightness • 2. RGB – Red, Green, Blue A. SIVASANKARI - SIASC-TVM
  • 29. PROGRAMMING IN JAVA Example: • Get red(); • int getgreen(); • int getblue(); • int getrgb(); WORKING WITH FONTS • Fonts have a family name, logical name and face name. • Family namily General name of font • Example: Courier • Logical name Category of font • Example: monospaced • Face name Specific font • Example: Courier italic • Syntax are methods : • String getfamily(); String getname(); Int get style(); • Boolean is Bold(); • Syntax: Font(String font name, int fontstyle, int pointsize) • Ex: Void setfont(font fontobject) A. SIVASANKARI - SIASC-TVM
  • 30. A. SIVASANKARI - SIASC-TVM