Professional Documents
Culture Documents
The basic concepts of exception handling are throwing an exception and catching it.
1
Java uses a keyword try to preface a block of code that is likely to cause an error
condition and “throw” an exception.
A catch block defined by the keyword catch “catches” the exception “thrown” by
three try block and handles it appropriately.
The catch block is added immediately after the try block.
Syntax Example
………….. try
………….. { x =a / ( b-c ) //Exception here
try }
{ statement; // generates an exception Catch ( ArthmeticException e)
} { System.out.println(“Division by zero”);
Catch (Exception – type e) }
{statement ; //process the exception
}
………….
………….
***********************************************************************
2
try { try {
- ----- - -----
- - - - -} - - - - -}
finally { Catch ( ……..)
---- {- - - - -
---- } - - - - -}
finally {
----
---- }
*****************************************************
3
The paint () method of the Applet class, when it is called, actually displays the
result of the applet code on the screen.
Syntax:
Public void paint (Graphics g)
*******************************************************************
4. Explain Applet Life Cycle
Every Java applet inherits a set of default behaviors from the Applet class. As a
result, when an applet is loaded, it undergoes a series of changes in its states in
figure
Begin Born
(Lode Applet)
Stop ()
Start ()
Running Stopped
Idle
Display
Start ()
Paint ()
Destroy ()
Destroyed Dead
End
de Exit of browser
Initialization State.
Create objects needed by the applet
Load images or fonts
Set up colors
We must override the init() method:
4
public void init()
{ stmts; }
Running State
Applets enters the running state when the system calls the start ()
This occurs automatically after the applet is initialized.
public void start()
{ stmts; }
Display State
Applet moves to the display state whenever it has to perform some output
operations on the screen.
This happen immediately after the applet enters into the running state. The
paint () method is called to accomplish this task.
Public void paint (Graphics g)
{
…………
………… (Display statements)
}
*******************************************************
5
Item event is triggered at the selection or de-selection of an itemized or list elements
such as check box.
Text event is triggered when the text field is modified.
Window event is triggered whenever window related operations is performed such as
closing or activating a window
Key event is triggered when a key is pressed on the keyboard.
Event Listeners
The Event listeners object contains methods for receiving and processing event
notification send by the source objects.
These methods are implemented from the corresponding listener interface contain in
the java.awt.event packages.
Event Classes
All the events in java have a corresponding event classes, which is derived from one
single super class i.e event objects.
It is contain in the java.util packages.
The event object class contains
o getSource(): Return the event source.
o toString(): Returns a string containing information about the event source.
Hierarchy of event based classes
Java.utilEventObjec
t
Java.awt.AWTEvent
Java.awt.ActionEvent
Java.awt.event.itemevent
Java.awt.event.TextEvent
Java.awt.event.AdjustmentEven
t
Java.awt.event.ComponentEvent
Java.awt.event.InputEven
t
Java.awt.event.MouseEven
6 t
Graphics Methods
Draw Line ()
void drawLine( int startX, int startY , int endX, int endY) ;
The line begins with startX, startY and ends with endX and endY similar to your
co-ordinate points x1, x2 , y1 and y2.
Draw Arc ()
void drawArc(int top, int left, int width, int height, int startAngle, int sweepAngle );
****************************************************