2. JAVA BEANS:
A “Bean” is a reusable software component model based on sun’s java bean
specification that can be manipulated visually in a builder tool.
The term software component model describe how to create and use reusable
software components to build an application
Builder tool is nothing but an application development tool which lets you both to
create new beans or use existing beans to create an application.
To enrich the software systems by adopting component technology JAVA came up
with the concept called Java Beans.
Java provides the facility of creating some user defined components by
means of Bean programming.
3. Advantages of Java Beans:
•
• The java beans posses the property of “Write once and run anywhere”.
•
• Beans can work in different local platforms.
•
• Beans have the capability of capturing the events sent by other objects and vice versa enabling
object communication.
•
• The properties, events and methods of the bean can be controlled by the application developer.
(ex. Add new properties)
•
– Beans can be configured with the help of auxiliary software during design time.(no hassle at runtime)
•
– The configuration setting can be made persistent.(reused)
•
– Configuration setting of a bean can be saved in persistent storage and restored later.
4. • JavaBeans basic rules:
•
• A Java Bean should:
•
• be public , implements the Serializable interface ,have a no-arg constructor and be derived from
javax.swing.JComponent or java.awt.Component if it is visual.
•
• The classes and interfaces defined in the java.beans package enable you to create JavaBeans.
•
• The Java Bean components can exist in one of the following three phases of development:
•
• Construction phase
•
• Build phase
•
• Execution phase
5. • It supports the standard component architecture features of
Properties
•
• Events
•
• Methods
•
• Persistence.
•
• In addition Java Beans provides support for
•
• Introspection (Allows Automatic Analysis of a java beans)
Customization(To make it easy to configure a java beans component
6. • The JavaBean Component Specification:
•
• Customization: Is the ability of JavaBean to allow its properties to
be changed in build and execution phase. Persistence:- Is the ability
of JavaBean to save its state to disk or storage device and restore
the saved state when the JavaBean is reloaded.
•
• Communication:-Is the ability of JavaBean to notify change in its
properties to other JavaBeans or the container.
•
• Introspection:- Is the ability of a JavaBean to allow an external
application to query the properties,methods, and events supported
by it.
•
7. • Features of a JavaBean:
• Support for “introspection” so that a builder tool can
analyze how a bean works.
• Support for “customization” to allow the customisation of
the appearance and behaviour of a bean.
• Support for “events” as a simple communication metaphor
than can be used to connect up beans.
• Support for “properties”, both for customization and for
programmatic use.
• Support for “persistence”, so that a bean can save and
restore its customized state.
8. • Steps to Develop a User-Defined JavaBean:
• Create a directory for the new bean
• Create the java bean source file(s)
• Compile the source file(s)
• Create a manifest file
• Generate a JAR file
• Start BDK
• Load Jar file
• Test.
9. • Introspection:
•
• Introspection can be defined as the technique of obtaining information about
bean properties, events and methods. Without introspection, the JavaBeans
technology could not operate.
•
• Persistence:
•
• Persistence means an ability to save properties and events of user deffined beans
to non-volatile storage and retrieve later.That is the state of the bean is stored and
retrived.
•
• Property:
•
• A property is a subset of a Bean’s state. Examples of bean properties include color,
label, font, font size, and display size.
10. • Types of JavaBeans Properties:
•
• Simple properties:- Simple properties refer to the private variables of a JavaBean that can have only a single value.
Simple properties are retrieved and specified using the get and set methods respectively.
•
• Boolean properties:- A Boolean property is a property which is used to represent the values True or False. Let N be
the name of the property and T be the type of the value then the methods are
•
• public boolean isN();
•
• public void setN(boolean parameter); public Boolean getN();
•
• Indexed properties:- Indexed Properties consists of multiple values.If a simple property can hold an
•
• array of value they are no longer called simple butinstead indexed properties. An indexed property may expose
set/get methods to read/write one element in the array (so-called ’index getter/setter’) and/or so-called ’array
getter/setter’ which read/write the entire array.
•
• Bound properties:- A bean that has a bound property generates an event when the property is changed.
•
• Constrained properties:- It generates an event when an attempt is made to change its value.
11. • Handling Events in JavaBeans:
•
• Enables Beans to communicate and connect together.
•
• Beans generate events and these events can be sent to other
objects.
•
• Event means any activity that interrupts the current ongoing
activity.
•
• Example: mouse clicks, pressing key…
•
12. APPLETS
• Definition:
• Applet is a special type of small java program
that is embedded in the webpage to generate
the dynamic content.
• It runs inside the java enabled web browser
and works at client side.
13. • Difference between Applet and java application:
•
• An applet is a Java class that extends the java.applet.Applet class.
•
• A main method is not invoked on an applet, and an applet class will not define main.
•
• Applets are designed to be embedded within an HTML page.
•
• When a user views an HTML page that contains an applet, the code for the applet is
downloaded to the user's machine.
•
• A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a
separate runtime environment. The JVM on the user's machine creates an instance of the
applet class and invokes various methods during the applet's lifetime.
•
• Applets have strict security rules that are enforced by the Web browser. The security of an
applet is often referred to as sandbox security, comparing the applet to a child playing in a
sandbox with various rules that must be followed.
•
• Other classes that the applet needs can be downloaded in a single Java Archive JAR file.
15. • Advantage:
• Platform Independent.
• Applets don’t have compatibility issues with different versions of java.
• Applets cache quickly, that’s why there will be no latency in downloading of them.
• It can also be used for a real time application.
• They can pay out different type of action on client-side machine like-
• Playing sound
• Viewing images
•
• Get user input
•
• Get mouse clicks
•
• Get user keystrokes
•
• They increase interactivity for users.
•
• Java has constituted security, by this feature of java; an applet doesn’t produce any harmful activity.
•
• Database integration is another important advantage of applets.
16. • Disadvantage:
•
• Some browsers especially mobile browsers which are running on Apple IOS or Android don’t support applets run.
•
• If a proxy server is applied to web access, than automatically installation and update of Java can be failed, that’s why
applets can’t run with specific requirements unless Java is manually installed or updated.
•
• Applets don’t access client-side resources, like-
•
• Files
•
• Operating system
•
• Applets have to tag as trusted applets and they must be registered to APS (Applet Security Manager).
•
• Applet cannot work with native methods.
•
• Applet can only extract information about client-machine is its name, java version, OS, version.
18. • init() – Execution of an applet starts from here. It is coequal to born stage of a thread. This is the first method (it is called
before all other methods). A programmer can exploit this method to instantiate objects, initialize variables, setting
background and foreground colors in GUI etc. In this method Applet is created but remains inactive.
• start() – In this method Applet become active, and become eligible for processor time. Because an inactive Applet is not
eligible for processor time.
•
• 3. paint() – this method is requested instantly after the start () method, this method takes a java.awt.Graphics
object as parameter, this is the only place where a programmer can write his code.
•
• stop() – This method makes an Applet inactive temporarily, and it is called directly when the user moves off the page on
which the applet sits.
• 5. destroy() – In this method an Applet become dead, and it’s the best place to have cleanup code.
•
• destroy() method is called when the browser shuts down normally.
21. • java.awt.Graphics class provides many methods for
graphics programming.
• Commonly used methods of Graphics class:
• public abstract void drawString(String str, int x, int y):
is used to draw the specified string.
• public void drawRect(int x, int y, int width, int height):
draws a rectangle with the specified width and height.
• public abstract void fillRect(int x, int y, int width, int
height): is used to fill rectangle with the default color
and specified width and height.
22. • public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.
•
• public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified
width and height.
•
• public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2).
•
• public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
•
• public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or
elliptical arc.
•
• public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or
elliptical arc.
•
• public abstract void setColor(Color c): is used to set the graphics current color to the specified color.
•
• public abstract void setFont(Font font): is used to set the graphics current font to the specified font.
•
23. • Adding images to Applet:
•
• First step is to create the image's URL object by calling either the getDocumentBase() or getCodeBase()
method. The former returns the URL of the directory from which the current HTML file was loaded,
•
• whereas the latter returns the URL of the directory from which the applet was run.
•
• public URL getDocumentBase(): is used to return the URL of the document in which applet is embedded.
• public URL getCodeBase(): is used to return the base URL.
• Create the Object for image using the function public Image getImage(URL u, String image){}
•
• Load the image in applet . public abstract boolean drawImage(Image img, int x, int y, ImageObserver
observer): is used draw the specified image.
24. • Other drawimage methods:
•
• drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
• Draws as much of the specified image as is currently available.
•
• drawImage(Image img, int x, int y, ImageObserver observer) Draws as much of the specified image as is currently available.
•
• drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) Draws as much of the specified
image as has already been scaled to fit inside the specified rectangle.
• drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
• Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
•
• drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
•
• Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the
specified area of the destination drawable surface.
• drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2,
• int sy2, ImageObserver observer)
•
• Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the
specified area of the destination drawable surface.