0% found this document useful (1 vote)
338 views42 pages

A Project Synopsis On Game of Chess: Submitted By: Shiva Chauhan Pankaj Kumar Pal Rahul Kumar Surendra Singh

The document provides an overview of the game of chess including its setup, history, and moves. It describes how chess is played on an 8x8 board with each player controlling 16 pieces including pawns, rooks, knights, bishops, queen, and king. The objective is to checkmate the opponent's king by placing it in a position where it is under attack and cannot escape. It also briefly outlines the basic moves for each piece and some key rules like checking the opponent's king and castling.

Uploaded by

vishalaroraccna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
338 views42 pages

A Project Synopsis On Game of Chess: Submitted By: Shiva Chauhan Pankaj Kumar Pal Rahul Kumar Surendra Singh

The document provides an overview of the game of chess including its setup, history, and moves. It describes how chess is played on an 8x8 board with each player controlling 16 pieces including pawns, rooks, knights, bishops, queen, and king. The objective is to checkmate the opponent's king by placing it in a position where it is under attack and cannot escape. It also briefly outlines the basic moves for each piece and some key rules like checking the opponent's king and castling.

Uploaded by

vishalaroraccna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

A Project Synopsis on

game of chess
Submitted By:

Shiva Chauhan

Pankaj Kumar Pal

Rahul Kumar

Surendra Singh
TABLE OF CONTENTS PAGES
 DECLARATION II
 CERTIFICATE III
 ACKNOWELDGEMENTS IV
 ABSTRACT V
 LIST OF FIGURES VI
 LIST OF ABBREVIATIONS VII
 CHAPTER 1

 Setup of game 5
 Moves 6
 Special moves 10
 Histroy 12
 Mathematics and Computers 14

 CHAPTER 2

 General Specifications 15
 Technical Specifications 16

 CHAPTER 3

 Abstract Window Toolkit 17


 Swing 20
 Snapshots of the Project 31
 Hardware Requirements 34
 Software Requirements 34
 Platform for the Project 35
 Data Flow Diagram 36

 REFERENCES 38
II

DECLARATION

We hereby declare that this project on the “ game of chess “ is our own work and
that to the best part of my knowledge and belief , it contains no material
previously published or written by another person nor material which to a
substantial content have been approved forward of any degree of this or any other
university .

Name : Shiva Chauhan

Pankaj Kumar Pal

Rahul Kumar

Surendra Singh

Date :07-05-2010
III

CERTIFICATE

This to certify that Project Report entitled “ Game of chess “ which is submitted by Shiva
Chauhan, Pankaj Kumar Pal, Rahul Kumar, Surendra Singh in partial fulfillment of
therequirement for the award of Diploma. in Department of the CSE

of Govt. Polytechnic Kashipur , is a record of the candidate own work carried out by

them under my supervision.

The matter embodied in this thesis is original and has not been submitted for the

award of any other degree.

Date : 07-05-2010 Submitted To :-

Miss. Anita Arya


IV

ACKNOWLEDGEMENT

We are indebted to Miss. Anita Arya , Senior Lecturer. in Information

Technology department , who had faith in this project & our technical

ability , whispered the words of encouragement and made helpful

suggestions from time to time .

We hope every student gets a mentor who is as cooperative , knowledgeable

and supportive as Miss. Anita Arya.

During the course of development of this project many people helped in

executing programs , spotting bugs and other developments.

I trust with our collective acumen , all programs would run correctly in all

Situations.

We thank our other faculty members for their constant support not only

during development of this project but throughout our engineering

Carrier.

And finally my heartfelt gratitude to our parents and our friends for

encouraging us in every step of our life .


V

ABSTRACT

This project is on the Game of Chess . Chess a very popular game throughout

the world and this project presents the software for playing the game on the

computer . The game is essentially designed for only 2 players at a time in

accordance to the rule of the game . Platform for the development of the project

is JAVA . Since main necessity for the development of this project was a easy to

use and effective GUI , and JAVA provides an excellent GUI through AWT and

Swing . Therefore , JAVA proved to be the perfect platform for the development

of this project .

Since JAVA is a platform independent language , it add another marvelous feature

to this software that it may run on any operating system .

Regarding the coding for the software , as described earlier all coding is done in

JAVA . There are 15 different modules in the project and all are linked to each

other through predefined and self - defined packages .


VI

List of Figures

 Setup of the game


 Moves :
o Moves of king
o Moves of rook
o Moves of bishop
o Moves of queen
o Moves of knight
o Moves of pawn

 Castling
 Special Pawn moves
 Snapshots of the project
 Data Flow Diagrams

VII

LIST OF ABBREVIATIONS

 AWT Abstract Window Toolkit


 API Application Program Interface
 GUI Graphical User Interface
 JFC Java Foundation Classes
 RAM Random Access Memory
 MB Mega Bytes
 JDK Java Developer’s Kit
 DFD Data Flow Diagram


1

DEVELOPER’S INFORMATION

Project Title GAME OF CHESS

Developer’s Name Shiva Chauhan, Pankaj Kumar Pal,

Rahul Kumar, Surendra Singh

College Address G.P. Kashipur

Duration : 1 Semesters

Development Platform : JAVA


4

GAME OF CHESS
Chess is a recreational and competitive game played between two players. The
current form of the game emerged in Southern Europe during the second half of
the 15th century after evolving from similar, much older games of Indian and
Persian origin. Today, chess is one of the world's most popular games, played by
millions of people worldwide at home, in clubs, online, by correspondence, and in
tournaments.

The game is played on a square chequered chessboard with 64 squares arranged in


an eight-by-eight grid. At the start, each player (one controlling the white pieces,
the other controlling the black pieces) controls sixteen pieces: one king, one
queen, two rooks, two knights, two bishops, and eight pawns. The object of the
game is to checkmate the opponent's king, whereby the king is under immediate
attack (in "check") and there is no way to remove it from attack on the next move.

The tradition of organized competitive chess started in the 16th century and has
developed extensively. Chess today is a recognized sport of the International
Olympic Committee. The first official World Chess Champion, Wilhelm Steinitz,
claimed his title in 1886; Viswanathan Anand is the current World Champion.
Theoreticians have developed extensive chess strategies and tactics since the
game's inception. Aspects of art are found in chess composition.

One of the goals of early computer scientists was to create a chess-playing


machine. Today's chess is deeply influenced by the abilities of current chess
programs and the ability to play against others online. In 1997, Deep Blue became
the first computer to beat the reigning World Champion in a match when it
defeated Garry Kasparov.
5

Setup of game

Initial position: first row: rook, knight, bishop, queen, king, bishop, knight, and rook; second
row: pawns

Chess is played on a square board of eight rows (called ranks and denoted with numbers 1 to 8)
and eight columns (called files and denoted with letters a to h) of squares. The colors of the
sixty-four squares alternate and are referred to as "light squares" and "dark squares". The
chessboard is placed with a light square at the right hand end of the rank nearest to each player,
and the pieces are set out as shown in the diagram, with each queen on its own color.

The pieces are divided, by convention, into white and black sets. The players are referred to as
"White" and "Black", and each begins the game with sixteen pieces of the specified color. These
consist of one king, one queen, two rooks, two bishops, two knights and eight pawns.

White always moves first. The players alternate moving one piece at a time (with the exception
of castling, when two pieces are moved simultaneously). Pieces are moved to either an
unoccupied square, or one occupied by an opponent's piece, capturing it and removing it from
6

play. With one exception (en passant), all pieces capture opponent's pieces by moving to the
square that the opponent's piece occupies.

When a king is under immediate attack by one or two of the opponent's pieces, it is said to be in
check. The only permissible responses to a check are to capture the checking piece, interpose a
piece between the checking piece and the king, or move the king to a square where it is not
under attack. Castling is not a permissible response to a check. A move that would place the
moving player's king in check is illegal. The object of the game is to checkmate the opponent;
this occurs when the opponent's king is in check, and there is no way to remove it from attack.

MOVES
Each chess piece has its own style of moving. The Xs mark the squares where the piece can
move if no other pieces (including one's own piece) are on the Xs between the piece's initial
position and its destination. If there is an opponent's piece at the destination square, then the
moving piece can capture the opponent's piece. The only exception is the pawn which can only
capture pieces diagonally forward.

Moves of a king
7
Moves of a rook

Moves of a bishop

8
Moves of a Queen

Moves of a knight

9
Moves of a pawn

Special moves

Castling

10
Once in every game, each king is allowed to make a special move, known as castling. Castling
consists of moving the king two squares towards a rook, then placing the rook immediately on
the far side of the king. Castling is only permissible if all of the following conditions hold:[1]

 Neither of the pieces involved in the castling may have been previously moved during the
game;
 There must be no pieces between the king and the rook;
 The king may not currently be in check, nor may the king pass through squares that are under
attack by enemy pieces. As with any move, castling is illegal if it would place the king in check.
 The king and the rook must be on the same rank

En passant

When a pawn advances two squares, if there is an opponent's pawn on an adjacent file next to
its destination square, then the opponent's pawn can capture it and move to the square the pawn
passed over, but only on the next move. For example, if the black pawn has just advanced two
squares from f7 to f5, then the white pawn on e5 can take it via en passant on f6.

Special pawn moves

The pawn on c7 can promote.


If Black's last move was ...f7-f5, White's e-pawn may capture the Black pawn en passant.

10

11
Promotion

When a pawn advances to its eighth rank, it is exchanged for the player's choice of a queen,
rook, bishop, or knight of the same color. Usually, the pawn is chosen to be promoted to a
queen, but in some cases another piece is chosen, called underpromotion. In the diagram on the
right, the pawn on c7 can choose to advance to the eighth rank to promote to a better piece.

End of the game

Chess games do not have to end in checkmate — either player may resign if the situation looks
hopeless. If it is a timed game a player may run out of time and lose, even with a much superior
position. Games also may end in a draw (tie). A draw can occur in several situations, including
draw by agreement, stalemate, threefold repetition of a position, the fifty-move rule, or a draw
by impossibility of checkmate (usually because of insufficient material to checkmate).

12
History

Predecessors

Chess originated in India during the Gupta empire, where its early form in the 6th century was
known as caturaṅga, which translates as "four divisions [of the military]" – infantry, cavalry,
elephants, and chariotry, represented by the pieces that would evolve into the modern pawn,
knight, bishop, and rook, respectively. Both the Persians and Arabs attribute the game of chess
to the Indians.[17] In Sassanid Persia around 600 the name became shatranj and the rules were
developed further. Shatranj was taken up by the Muslim world after the Islamic conquest of
Persia, with the pieces largely retaining their Persian names. In Spanish "shatranj" was rendered
as ajedrez, in Portuguese as xadrez, and in Greek as zatrikion, but in the rest of Europe it was
replaced by versions of the Persian shāh ("king"), which was familiar as an exclamation and
became our words "check and chess". Murray theorized that this change happened from Muslim
traders coming to European seaports with ornamental chess kings as curios before they brought
the game of chess.

The game reached Western Europe and Russia by at least three routes, the earliest being in the
9th century. By the year 1000 it had spread throughout Europe.Introduced into the Iberian
Peninsula by the Moors in the 10th century, it was described in a famous 13th-century
manuscript covering shatranj, backgammon, and dice named the Libro de los juegos

Birth of Sport
The first modern chess tournament was held in London in 1851 and won, surprisingly, by
German Adolf Anderssen, relatively unknown at the time. Anderssen was hailed as the leading
chess master and his brilliant, energetic attacking style became typical for the time, although it
was later regarded as strategically shallow.Sparkling games like Anderssen's Immortal game or
Morphy's Opera game were regarded as the highest possible summit of the chess art.

Deeper insight into the nature of chess came with two younger players. American Paul Morphy,
an extraordinary chess prodigy, won against all important competitors, including Anderssen,

13
during his short chess career between 1857 and 1863. Morphy's success stemmed from a
combination of brilliant attacks and sound strategy; he intuitively knew how to prepare attacks.
[32]
Prague-born Wilhelm Steinitz later described how to avoid weaknesses in one's own position
and how to create and exploit such weaknesses in the opponent's position. In addition to his
theoretical achievements, Steinitz founded an important tradition: his triumph over the leading
German master Johannes Zukertort in 1886 is regarded as the first official World Chess
Championship. Steinitz lost his crown in 1894 to a much younger German mathematician
Emanuel Lasker, who maintained this title for 27 years, the longest tenure of all World
Champions.

Wilhelm Steinitz, the first World Chess Champion

It took a prodigy from Cuba, José Raúl Capablanca (World champion 1921–27), who loved
simple positions and endgames, to end the German-speaking dominance in chess; he was
undefeated in tournament play for eight years until 1924. His successor was Russian-French
Alexander Alekhine, a strong attacking player, who died as the World champion in 1946,
having briefly lost the title to Dutch player Max Euwe in 1935 and regaining it two years later.

Between the world wars, chess was revolutionized by the new theoretical school of so-called
hypermodernists like Aron Nimzowitsch and Richard Réti. They advocated controlling the
center of the board with distant pieces rather than with pawns, inviting opponents to occupy the
center with pawns which become objects of attack.[36]

After the end of the 19th century, the number of annually held master tournaments and matches
quickly grew. Some sources state that in 1914 the title of chess grandmaster was first formally
conferred by Tsar Nicholas II of Russia to Lasker, Capablanca, Alekhine, Tarrasch and
Marshall, but this is a disputed claim.[37] The tradition of awarding such titles was continued by
the World Chess Federation (FIDE), founded in 1924 in Paris. In 1927, Women's World Chess
Championship was established; the first to hold it was Czech-English master Vera Menchik.[38]
14

Mathematics and computers


The game structure and nature of chess is related to several branches of mathematics. Many
combinatorical and topological problems connected to chess were known of for hundreds of
years. In 1913, Ernst Zermelo used it as a basis for his theory of game strategies, which is
considered as one of the predecessors of game theory.

The number of legal positions in chess is estimated to be between 1043 and 1050, with a game-
tree complexity of approximately 10123. The game-tree complexity of chess was first calculated
by Claude Shannon as 10120, a number known as the Shannon number. Typically an average
position has thirty to forty possible moves, but there may be as few as zero (in the case of
checkmate or stalemate) or as many as 218.

The most important mathematical challenge of chess is the development of algorithms which
can play chess. The idea of creating a chess playing machine dates to the 18th century; around
1769, the chess playing automaton called The Turk became famous before being exposed as a
hoax. Serious trials based on automatons, such as El Ajedrecista, were too complex and limited
to be useful.

Since the advent of the digital computer in the 1950s, chess enthusiasts and computer engineers
have built, with increasing degrees of seriousness and success, chess-playing machines and
computer programs. The groundbreaking paper on computer chess, "Programming a Computer
for Playing Chess", was published in 1950 by Shannon.He wrote:

15
About the project
General Specifications
 The game of chess can be played between 2 players.
 The game can be played on any operating system.
 There is no provision for single player game in the game.
 There appears error message for every illegal / wrong step.
 There is no provision for a undo to create a more realistic experience.
 A congrates message is displayed when a player win.

16
Technical Specifications
 Project is Platform Independent.
 Project is build up using JDK 1.5.1.
 GUI components of the project are provide by AWT , Swings.
 To run the project there must be JDK installed .
 Steps for running the project :-
I. Open command interpreter
II. Specify the path for the “Chess”
folder
III. Type javac chess.java
IV. Type java chess

17
Abstract Window Toolkit
The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing,
graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation
Classes (JFC) — the standard API for providing a graphical user interface (GUI) for a Java
program.

AWT is also the GUI toolkit for a number of Java ME profiles. For example, Connected Device
Configuration profiles require Java runtimes on mobile telephones to support AWT.

Architecture

The AWT provides two levels of APIs:

 A general interface between Java and the native system, used for windowing, events, layout
managers. This API is at the core of Java GUI programming and is also used by Swing and Java
2D. It contains:
o The interface between the native windowing system and the Java application;
o The core of the GUI event subsystem;
o Several layout managers;

18
o The interface to input devices such as mouse and keyboard; and
o A java.awt.datatransfer package for use with the Clipboard and Drag and Drop.

 A basic set of GUI widgets such as buttons, text boxes, and menus. It also provides the AWT
Native Interface, which enables rendering libraries compiled to native code to draw directly to
an AWT Canvas object drawing surface.

AWT also provide some miscellaneous useful utilities, that can also be used by Swing, such as:

 Access to the system tray on supporting systems; and


 The ability to launch some desktop applications such as web browsers and email clients from a
Java application.

Neither AWT nor Swing are inherently thread safe. Therefore, code that updates the GUI or
processes events should execute on the Event dispatching thread. Failure to do so may result in
a deadlock or race condition. To address this problem, a utility class called SwingWorker allows
applications to perform time-consuming tasks following user-interaction events in the event
dispatching thread.

Mixing AWT and Swing components

Prior to Java 6 Update 12, mixing Swing components and AWT basic widgets has often resulted
in undesired side effects, with AWT widgets going on top of the Swing widgets regardless of
their defined priorities. This problem was due to the fact that the rendering architecture of the
two widgets toolkit was very different, despite Swing borrowing heavyweight top containers
from AWT.

Since Java 6 Update 12, it is now possible to mix Swing and AWT widgets without having
priorities problems

Window Fundamentals
The AWT defines windows according to a class hierarchy that adds functionality and
specificity with each level. The two most common windows are those derived from
Panel, which is used by applets, and those derived from Frame, which creates a
standard window. Much of the functionality of these windows is derived from their
parent classes. Thus, a description of the class hierarchies relating to these two classes

19
is fundamental to their understanding.

Component
At the top of the AWT hierarchy is the Component class. Component is an abstract
class that encapsulates all of the attributes of a visual component. All user interface
elements that are displayed on the screen and that interact with the user are subclasses
of Component. It defines over a hundred public methods that are responsible for
managing events, such as mouse and keyboard input, positioning and sizing the
window, and repainting. A Component object is responsible for remembering
the current foreground and background colors and the currently selected text font.

Container
The Container class is a subclass of Component. It has additional methods that allow
other Component objects to be nested within it. Other Container objects can be stored
inside of a Container (since they are themselves instances of Component). This makes
for a multileveled containment system.

Panel
The Panel class is a concrete subclass of Container. It doesn’t add any new methods; it
simply implements Container. A Panel may be thought of as a recursively nestable,
concrete screen component. Panel is the superclass for Applet. When screen output is
directed to an applet, it is on the surface of a Panel object. In essence, a Panel is
a window that does not contain a title bar, menu bar, or border. This is why you don’t
see these items when an applet is run inside a browser. When you run an applet using

an applet viewer, the applet viewer provides the title and border.
Other components can be added to a Panel object by its add( ) method (inherited
from Container). Once these components have been added, you can position and resize
them manually using the setLocation( ), setSize( ), or setBounds( ) methods defined by component.
Window
The Window class creates a top-level window. A top-level window is not contained
within any other object; it sits directly on the desktop.

Frame
Frame encapsulates what is commonly thought of as a “window.” It is a subclass of
Window and has a title bar, menu bar, borders, and resizing corners. If you create a
Frame object from within an applet, it will contain a warning message, such as “Java
Applet Window,” to the user that an applet window has been created. This message
warns users that the window they see was started by an applet and not by software
running on their computer. (An applet that could masquerade as a host-based
application could be used to obtain passwords and other sensitive information without
the user’s knowledge.) When a Frame window is created by a program rather than an
applet, a normal window is created.

20
Swing
Swing is a widget toolkit for Java. It is part of Sun Microsystems' Java Foundation Classes
(JFC) — an API for providing a graphical user interface (GUI) for Java programs,

Swing was developed to provide a more sophisticated set of GUI components than the earlier
Abstract Window Toolkit. Swing provides a native look and feel that emulates the look and feel
of several platforms, and also supports a pluggable look and feel that allows applications to
have a look and feel unrelated to the underlying .

Architecture

Swing is a platform-independent, Model-View-Controller GUI framework for Java. It follows a


single-threaded programming model, and possesses the following traits:

Foundations

Platform independence

Swing is platform independent both in terms of its expression (Java) and its implementation
(non-native universal rendering of widgets).

Extensibility

Swing is a highly partitioned architecture, which allows for the "plugging" of various custom
implementations of specified framework interfaces: Users can provide their own custom
implementation(s) of these components to override the default implementations. In general,
Swing users can extend the framework by extending existing (framework) classes and/or
providing alternative implementations of core components.

Component Oriented

Swing is a component-based framework. The distinction between objects and components is a


fairly subtle point: concisely, a component is a well-behaved object with a known/specified
characteristic pattern of behaviour. Swing objects asynchronously fire events, have "bound"
properties, and respond to a well-known set of commands (specific to the component.)
Specifically, Swing components are Java Beans components, compliant with the Java Beans
Component Architecture specifications.

21
Customizable

Given the programmatic rendering model of the Swing framework, fine control over the details
of rendering of a component is possible in Swing. As a general pattern, the visual representation
of a Swing component is a composition of a standard set of elements, such as a "border",
"inset", decorations, etc. Typically, users will programmatically customize a standard Swing
component (such as a JTable) by assigning specific Borders, Colors, Backgrounds, opacities,
etc., as the properties of that component. The core component will then use these property
(settings) to determine the appropriate renderers to use in painting its various aspects. However,
it is also completely possible to create unique GUI controls with highly customized visual
representation.

Configurable

Swing's heavy reliance on runtime mechanisms and indirect composition patterns allows it to
respond at runtime to fundamental changes in its settings. For example, a Swing-based
application can change its look and feel at runtime. Further, users can provide their own look
and feel implementation, which allows for uniform changes in the look and feel of existing
Swing applications without any programmatic change to the application code.

The JComponent Class


With the exception of top-level containers, all Swing components whose names begin with "J"
descend from the JComponent class. For example, JPanel, JScrollPane, JButton, and JTable
all inherit from JComponent. However, JFrame and JDialog don't because they implement top-
level containers.

The JComponent class extends the Container class, which itself extends Component. The
Component class includes everything from providing layout hints to supporting painting and
events. The Container class has support for adding components to the container and laying
them out. This section's API tables summarize the most often used methods of Component and
Container, as well as of JComponent.

22
JComponent Features

The JComponent class provides the following functionality to its descendants:

 Tool tips
 Painting and borders
 Application-wide pluggable look and feel
 Custom properties
 Support for layout
 Support for accessibility
 Support for drag and drop
 Double buffering
 Key bindings

The JComponent API

The JComponent class provides many new methods and inherits many methods from
Component and Container. The following tables summarize the methods we use the most.

 Customizing Component Appearance


 Setting and Getting Component State
 Handling Events
 Painting Components
 Dealing with the Containment Hierarchy
 Laying Out Components
 Getting Size and Position Information
 Specifying Absolute Size and Position
23

Swings Methods & There Purpose

Customizing Component Appearance

Method Purpose

void setBorder(Border) Set or get the border of the component. See How to Use Borders for
Border getBorder() details.
void Set the foreground or background color for the component. The
setForeground(Color) foreground is generally the color used to draw the text in a component.
void The background is (not surprisingly) the color of the background areas
setBackground(Color) of the component, assuming that the component is opaque.
Color getForeground() Get the foreground or background color for the component.
Color getBackground()
void Set or get whether the component is opaque. An opaque component fills
setOpaque(boolean) its background with its background color.
boolean isOpaque()
void setFont(Font) Set or get the component's font. If a font has not been set for the
Font getFont() component, the font of its parent is returned.
void setCursor(Cursor) Set or get the cursor displayed over the component and all components
Cursor getCursor() it contains (except for children that have their own cursor set).
24

Setting and Getting Component State

Method Purpose

void Sets the JPopupMenu for this JComponent. The UI is


setComponentPopupMenu(String) responsible for registering bindings and adding the necessary
listeners such that the JPopupMenu will be shown at the
appropriate time. When the JPopupMenu is shown depends
upon the look and feel: some may show it on a mouse event,
some may enable a key binding.
void setToolTipText(String) Set the text to display in a tool tip. See How to Use Tool Tips
for more information.
void setName(String) Set or get the name of the component.
String getName()
boolean isShowing() Determine whether the component is showing on screen. This
means that the component must be visible, and it must be in a
container that is visible and showing.
void setEnabled(boolean) Set or get whether the component is enabled. An enabled
boolean isEnabled() component can respond to user input and generate events.
void setVisible(boolean) Set or get whether the component is visible. Components are
boolean isVisible() initially visible, with the exception of top-level components.

25
Handling Events

Method Purpose

void addHierarchyListener(hierarchyListener l) Adds or removes the specified hierarchy


void removeHierarchyListener(hierarchyListener l)
listener to receive hierarchy changed
events from this component when the
hierarchy to which this container belongs
changes. If listener l is null, no exception
is thrown and no action is performed.
void addMouseListener(MouseListener) Add or remove a mouse listener to or from
void removeMouseListener(MouseListener) the component. Mouse listeners are
notified when the user uses the mouse to
interact with the listened-to component.
void Add or remove a mouse motion listener to
addMouseMotionListener(MouseMotionListener) or from the component. Mouse motion
void listeners are notified when the user moves
removeMouseMotionListener(MouseMotionListener) the mouse within the listened-to
component's bounds.
void addKeyListener(KeyListener) Add or remove a key listener to or from
void removeKeyListener(KeyListener) the component. Key listeners are notified
when the user types at the keyboard and
the listened-to component has the
keyboard focus.
void addComponentListener(ComponentListener) Add or remove a component listener to or
void removeComponentListener(ComponentListener) from the component. Component listeners
are notified when the listened-to
component is hidden, shown, moved, or
resized.
boolean contains(int, int) Determine whether the specified point is
boolean contains(Point) within the component. The argument

should be specified in terms of the


component's coordinate .
Component getComponentAt(int, int) Return the component that contains the
Component getComponentAt(Point) specified x, y position. The top-most child
component is returned in the case where
components overlap.
26
Painting Components

Method Purpose

void repaint() Request that all or part of the component be repainted. The four
void repaint(int, int, int, int) int arguments specify the bounds (x, y, width, height, in that
order) of the rectangle to be painted.
void repaint(Rectangle) Request that the specified area within the component be repainted.
void revalidate() Request that the component and its affected containers be laid out
again. You should not generally need to invoke this method unless
you explicitly change a component's size/alignment hints after it's
visible or change a containment hierarchy after it is visible.
void Paint the component. Override this method to implement painting
paintComponent(Graphics) for custom components.

27
Dealing with the Containment Hierarchy

Method Purpose
Component add(Component) Add the specified component to this
Component add(Component, int) container. The one-argument version
void add(Component, Object) of this method adds the component to
the end of the container.

void remove(int) Remove one of or all of the


void remove(Component) components from this container. When
void removeAll() present, the int argument indicates the
position within the container of the
component to remove.
JRootPane getRootPane() Get the root pane that contains the
component.
Container getTopLevelAncestor() Get the topmost container for the
component — a Window, Applet, or
null if the component has not been
added to any container.
Container getParent() Get the component's immediate
container.
int getComponentCount() Get the number of components in this
container.
Component getComponent(int) Get the one of or all of the components
Component[] getComponents() in this container. The int argument
indicates the position of the
component to get.
Component getComponentZOrder(int) Returns the z-order index of the
Component[] getComponentZOrder() component inside the container. The
higher a component is in the z-order
hierarchy, the lower its index.

28

Laying Out Components


Method Purpose
void setPreferredSize(Dimension) Set the component's preferred,
void setMaximumSize(Dimension) maximum, or minimum size,
void setMinimumSize(Dimension) measured in pixels. The preferred size
indicates the best size for the
component.
Dimension getPreferredSize() Get the preferred, maximum, or
Dimension getMaximumSize() minimum size of the component,
Dimension getMinimumSize() measured in pixels.
void setAlignmentX(float) Set the alignment along the x- or y-
void setAlignmentY(float) axis. These values indicate how the
component would like to be aligned
relative to other components. The
value should be a number between 0
and 1 where 0 represents alignment
along the origin .
float getAlignmentX() Get the alignment of the component
float getAlignmentY() along the x- or y- axis. For non-
JComponent subclasses, which do not
have the corresponding setter
methods, you can set a component's
alignment by creating a subclass and
overriding these methods.
void setLayout(LayoutManager) Set or get the component's layout
LayoutManager getLayout() manager. The layout manager is
responsible for sizing and positioning
the components within a container.
void Set the ComponentOrientation
applyComponentOrientation(ComponentOrientation) property of this container and all the
void setComponentOrientation(ComponentOrientation) components contained within it. See
Setting the Container's Orientation for
more information.

29
Getting Size and Position Information

Method
Purpose

int getWidth() Get the current width or height of the component measured in pixels.
int getHeight()
Get the current x or y coordinate of the component's origin relative to
int getX() the parent's upper left corner measured in pixels.
int getY()
Rectangle getBounds() Get the bounds of the component measured in pixels. The bounds
Rectangle specify the component's width, height, and origin relative to its parent.
getBounds(Rectangle) When using the one-argument version of this method, the caller is
responsible for creating the Rectangle instance in which the result is
returned.
Point getLocation() Gets the current location of the component relative to the parent's
Point getLocation(Point) upper left corner measured in pixels. When using the one-argument
version of getLocation method, the caller is responsible for creating
the Point instance in which the result is returned.
Point Returns the position relative to the upper left corner of the screen.
getLocationOnScreen()
Insets getInsets() Get the size of the component's border.

30

Relationship to AWT
Since early versions of Java, a portion of the Abstract Window Toolkit (AWT) has provided
platform-independent APIs for user interface components. In AWT, each component is
rendered and controlled by a native peer component specific to the underlying windowing
system.

By contrast, Swing components are often described as lightweight because they do not require
allocation of native resources in the operating system's windowing toolkit. The AWT
components are referred to as heavyweight components.

Much of the Swing API is generally a complementary extension of the AWT rather than a direct
replacement. In fact, every Swing lightweight interface ultimately exists within an AWT
heavyweight component because all of the top-level components in Swing (JApplet, JDialog,
JFrame, and JWindow) extend an AWT top-level container.

Hardware Requirements
 Pentium Processor II or higher with min. 800 Mhz.

 Min. 128 MB of RAM.


 700 MB free space in hard disk.

Software Requirement

 Java Development Kit ( JDK )

Platform for the project

The system has been developed using JAVA which is platform independent. This
allows the system to be independent of the platform being used to run the system.
Hence, whether a windows operating system is used or a Mac, or Linux operating
system is used the same performance of the system can ba availed of by the user.

Fundamentals of Java
 Java developed by Sun
 Sun describes Java as:
– Simple, Object-oriented, Distributed, Interpreted, Robust, Secure,
Architecture neutral, Portable, High-performance, Multithreaded, and
Dynamic Language

Tools Available for Java Programming


 Java Developer’s Kit (JDK)
– JDK from JavaSoft a division of Sun Microsystems Inc.
– Contains the basic tools and libraries necessary for creating, testing,
documenting and executing Java programs
– There are seven main programs in JDK
 javac – the Java Compiler
 java – the Java Interpreter
 javadoc – generates documentation in HTML
 appletviewer – the Java Interpreter to execute Java applets
 jdb – the Java Debugger to find and fix bugs in Java programs
 javap – the Java Disassembler to displays the accessible functions
and data in a compiled class; it also displays the meaning of byte
codes
 javah – to create interface between Java and C routines

Data Flow Diagram


REFERENCES

 Herbert Schildt , “The Complete Referencs JAVA Seventh Edition”

 Khalid A . Mughal , Rolf W . Rasmussen

 SUN’s JAVA tutorial

 Kathy Sierra & Bert Bates , “ Head First JAVA 2ND Edition ”

ka􀁂􀁕􀁉􀁚􀀁􀀴􀁊􀁆􀁓􀁓􀁂􀀁􀀇􀀁􀀣􀁆􀁓􀁕􀀁􀀣􀁂􀁕􀁆􀁔

You might also like