Вы находитесь на странице: 1из 4

Applet

 An Applet is a small application that are accessed through Internet


 It is developed and stored in a server machine.
 In response to the client request, Applet will send to the client machine.
 Java enabled browsers can display Applets
 Applet has limited acces to the resources in the client machine. Hence Applet
is free from the risk of virus and guarantee data integrity
Applet Creation
 An Applet is a graphical user interface
 GUI is designed using AWT(Abstract Window Toolkit) control
 Two versions of Windows controls
 AWT control
 SWING controls
 An Applet should be subclass of java.applet.Applet class and it should be
public
 An Applet does not contains main() method

The Delegation Event Model

 Standard and consistent mechanism to generate and process events


 Concept
 Source generates events and send to one or more listeners
 Listener waits for an event to occur
 When event happens, listener process the event and returns
 Hint: Listener must register in order to receive an event notification
 A user interface element is able to “delegate” the processing of an event to a
separate piece of code

 An event is an object that describes a state change in a source


 Events are generated
 As a consequence of a user interacting with GUI element
 As a consequence of a previous event
 Without any user interaction

Event Sources
 A source is an object that generates an event
 A source may generate more than one type event
 Source must register listeners in order for listener to receive notification
about the event
 General Form:
 public void addTypeListener(TypeListener obj)
 Listener can remove from source
 Eg: button1.removeMouseListener(this)
 All events has its own registration
Event Listeners

 A listener is an object that is notified when an event occurs


 An event listener must
 Registered with one or more sources to receive notification
 Implement methods to receive and process notifications
 These methods are defined as interfaces and found in java.awt.event
package
Event Classes

 EventObject
 Root class in the Java event hierarchy
 Found in java.util package
 Two methods: getSource(), toString()

Layout

 The way in which the controls of a container are arranged


 All the containers have default Layout
 Eg: Applet – FloweLayout.CENTER
 Eg: Frame – BorderLayout.CENTER
 Layout Manager: An instance of any class that implements the
LayoutManager interface
 Layout can set by using setLayout() method
 Eg: setLayout(layoutobj)
 Layout can be “null”; No default Layout manager
 Layout Manager will invoke
 Container is resized
 Add Component
 Layout Size
 minimumLayoutSize()
 prefferredLayoutSize()
 Component Size
 getPreferredSize()
 getMinimumSize()

FlowLayout

 Components are arranged as floating objects


 Small space will left between each component
 Class: FlowLayout
 FlowLayout()
 FlowLayout(int how)
 how
 FlowLayout.LEFT
 FlowLayout.CENTER
 FlowLayout.RIGHT
 FlowLayout(int how, int hSpze, int vSpze)
BorderLayout

 The container is divided into five regions


 BorderLayout.CENTER
 BorderLayout.EAST
 BorderLayout.WEST
 BorderLayout.SOUTH
 BorderLayout.NORTH
 Class: BorderLayout
 BorderLayout()
 BorderLayout(hSpz, vSpz)
 Adding Component
 add(component, region)

Using Insets

 Insets: Space between the container that holds component and the window
that contains it
 Override the getInsets() method to specify new dimension
 Insets(int top, int left, int bottom, int right)
 Eg:
public Insets getInsets()
{
return new Insets(10,10,10,10);
}
GridLayout
 Divides the container into two dimensional grid
 Class: GridLayout
 GridLayout() – Single column
 GridLayout(rows, cols)
 GridLayout(rows, cols,hSpz,vSpz)
 rows, cols can be zero, means it can have unlimited length

CardLayout

 More than one Layouts are managing at the same time


 Panel
 It is container
 not visible
 Can set Layout
 Class: CardLayout
 CardLayout()
 CardLayout(hSpz, vSpz)
 Steps
 Assign layout to top-level container in the program
 Create another container to hold the first group of controls
 Similarly create more containers to hold the subsequent group of
controls
 Recalling Cards
 Void first(Container deck)
 Void last(Container deck)
 Void next(Container deck)
 Void previous(Container deck)
 Void show(Container deck, String cardName)

Вам также может понравиться