Jprlastyrp
Jprlastyrp
Jprlastyrp
Sr.
Characteristic to be Poor Average Good Excellent
No.
assessed (Marks 1-3) (Marks 4-5) (Marks 6 - 8) (Marks 9-10)
(A) Process and Product Assesssment (Convert above total marks out of 6 marks)
1 Relevance to the Course
Literature Survey /
2
Information Collection
Completion of the Target as
3
per project proposal
Analysis of data and
4
representation
5 Quality of Prototype / Model
6 Report Preparation
(B) Individual Presentation / Viva (Convert above total marks out of 4 marks)
8 Presentation
9 Viva
Micro – Project Evaluation Sheet:
Process Assessment Product Assessment
Part Project Part Individual Total
A – project Methodology B – Project Presentation / Marks 10
Name of Student Proposal (2 marks) Report / Working Viva (4 marks)
(2 marks) Model(2 marks)
1
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION
SHRI H. H. J. B POLYTECHNIC,
CHANDWAD-423101 (Nashik)
MICRO PROJECT
Academic year 2024-25
TITLE OF PROJECT
Exploring BorderLayout and FlowLayout
code:22517
3
MAHARASHTRA STATE BOARD OF TECHNICALEDUCATION
CERTIFICATE
This is to certify that :
Place: CHANDWAD
Date: / /2024
4
INDEX
Part B
5
PART A-Plan
Title of micro-project: Exploring BorderLayout and FlowLayout
Although somewhat surprisingly, the original impetus for Java was not the
Internet! Instead, the primary motivation was the need for a platform-independent
(that is, architecture-neutral) language that could be used to create software to be
embedded in various consumer electronic devices, such as microwave ovens and
remote controls. However, with the emergence of the World Wide Web, Java was
propelled to the forefront of computer language design, because the Web, too,
demanded portable programs. After that the Internet helped catapult Java to the
forefront of programming, and Java, in turn, had a profound effect on the Internet. In
addition to simplifying web programming in general, Java innovated a new type of
networked program called the Applet that changed the way the online world thought
about content.
6
4.0 Resources Required:
7
PART B-Plan
An applet is a special kind of Java program that is designed to be transmitted over the
Internet and automatically executed by a Java-compatible web browser. The Applet class,
provides the foundation for applets. The Applet class is contained in the java.applet package.
Applet contains several methods that give you detailed control over the execution of your
applet.
All applets are subclasses (either directly or indirectly) of Applet. Thus, all applets must
import java.applet. Applets must also import java.awt. AWT stands for the Abstract Window
Toolkit. Since all applets run in a window, it is necessary to include support for that window by
importing java.awt package.
Execution of an applet does not begin at main( ). Output to your applet’s window is not
performed by System.out.println( ). Rather, it is handled with various AWT methods, such as
drawString( ), which outputs a string to a specified X,Y location. Input is also handled differently
than in a console application.
Once an applet has been compiled, it is included in an HTML file using theAPPLET tag.
The applet will be executed by a Java-enabled web browser when it encounters the APPLET tag
within the HTML file.
To view and test an applet more conveniently, simply include a comment at the head of
your Java source code file that contains the APPLET tag.
Here is an example of such a comment:
/*
<applwt code= ”MyApplet” width =200 height=60>
</applet>
*/
This comment contains an APPLET tag that will run an applet called MyApplet in a
window that is 200 pixels wide and 60 pixels high. Since the inclusion of an APPLET command
makes testing applets easier, all of the applets shown in this tutorial will contain the appropriate
APPLET tag embedded in a comment.
8
The Applet Class: Applet extends the AWT class Panel. In turn, Panel extends
Container, which extends Component.
These classes provide support for Java’s window-based, graphical interface. Thus, Applet
provides all of the necessary support for window-based activities.
These five methods can be assembled into the skeleton shown here:
// An Applet skeleton.
import java.awt.*;
import java.applet.*;
/*
<applet code= “AppletSkel” width=300 height=100>
9
</applet>
*/
public class AppletSkel extends Applet
{
// Called first.
public void init()
{
// initialization
}
/* Called second, after init(). Also called whenever
the applet is restarted. */
public void start()
{
// start or resume execution
}
// Called when the applet is stopped.
public void stop()
{
// suspends execution
}
/* Called when applet is terminated. This is the last
method executed. */
public void destroy()
{
// perform shutdown activities
}
// Called when an applet's window must be restored.
public void paint(Graphics g)
{
// redisplay contents of window
}
}
Applet Life Cycle: The life cycle of an applet is as shown in the figure below:
As shown in the above diagram, the life cycle of an applet starts with init() method and ends
with destroy() method. Other life cycle methods are start(), stop() and paint(). The methods to
execute only once in the applet life cycle are init() and destroy(). Other methods execute
multiple times.
Below is the description of each applet life cycle method:
10
init():The init( ) method is the first method to be called. This is where you should
initialize variables. This method is called only once during the run time of your
applet.
start():The start( ) method is called after init( ). It is also called to restart an applet after
it has been stopped. Whereas init( ) is called once—the first time an applet is loaded—
start( ) is called each time an applet’s HTML document is displayed onscreen. So, if a
user leaves a web page and comes back, the applet resumes execution at start( ).
paint():The paint( ) method is called each time your applet’s output must be
redrawn. This situation can occur for several reasons. paint( ) is also called when the
applet begins execution. Whatever the cause, whenever the applet must redraw its
output, paint( ) is called. The paint( ) method has one parameter of type Graphics.
stop():The stop( ) method is called when a web browser leaves the HTML document
containing the applet—when it goes to another page, for example. When stop( ) is
called, the applet is probably running. You should use stop( ) to suspend threads that
don’t need to run when the applet is not visible. You can restart them when start( )
is called if the user returns to the page.
destroy():The destroy( ) method is called when the environment determines that your
applet needs to be removed completely from memory. At this point, you should free up
any resources the applet may be using. The stop( ) method is always called before
destroy( ).
Overriding update( ): In some situations, your applet may need to override another
method defined by the AWT, called update( ). This method is called when your applet
has requested that a portion of its window be redrawn. The default version of update( )
simply calls paint( ). However, you can override the update( ) method so that it
performs more subtle repainting. In general, overriding update( ) is a specialized
technique that is not applicable to all applets, and the examples in this book do not
override update( ).
The method execution sequence when an applet is executed is:
• init()
• start()
• paint()
The method execution sequence when an applet is closed is:
• stop()
• destroy()
How To Run an Applet Programe: There are two ways in which you can run an
applet:
■ Executing the applet within a Java-compatible Web browser.
■ Using an applet viewer, such as the standard SDK tool, appletviewer. An applet
viewer executes your applet in a window. This is generally the fastestand easiest way to
test your applet.
Using an applet viewer to run applet
Place the applet tag in comments in java source code.
Note:Code attribute value must be equal to name of class which extends Applet class.
12
void repaint(long maxDelay)
void repaint(long maxDelay, int x, int y, int width, int height)
Here, maxDelay specifies the maximum number of milliseconds that can elapse before update()
is called.
ALT :The ALT tag is an optional attribute used to specify a short text message that should be
displayed if the browser understands the APPLET tag but can’t currently run Java applets.
NAME: NAME is an optional attribute used to specify a name for the applet instance. Applets
must be named in order for other applets on the same page to find them by name and
communicate with them.
WIDTH AND HEIGHT :WIDTH and HEIGHT are required attributes that give the size (in pixels) of
the applet display area.
ALIGN: ALIGN is an optional attribute that specifies the alignment of the applet.The possible
values:LEFT, RIGHT, TOP, BOTTOM, MIDDLE, BASELINE, TEXTTOP, ABSMIDDLE,and
ABSBOTTOM.
VSPACE AND HSPACE :These attributes are optional. VSPACE specifies the space, in pixels,
above and below the applet. HSPACE specifies the space, in pixels, on each side of the applet.
13
PARAM NAME AND VALUE: The PARAM tag allows you to specify applet specific arguments in
an HTML page. Applets access their attributes with the getParameter( ) method.
14
6.0 A Simple Applet Programme to display a Clock:
import java.applet.*;
import java.awt.*;
import java.util.*;
public class Clock extends Applet implements Runnable
{
Thread t;
//Initialize the applet
public void init()
{
setBackground(Color.white);
}
//Function to start the thread
public void start()
{
t = new Thread(this);
t.start();
}
//Function to execute the thread
public void run()
{
while(true)
{
Try
{
repaint();
//Delay by 1 sec
Thread.sleep(1000);
}
catch(Exception e)
{
}
}
}
//Function to draw the clock
public void paint(Graphics g)
{
Calendar time = Calendar.getInstance();
int hour = time.get(Calendar.HOUR_OF_DAY) % 12;
int minute = time.get(Calendar.MINUTE);
int second = time.get(Calendar.SECOND);
double angle;
int x,y;
//Draw a circle with center(250,250) & radius=150
g.drawOval(100,100,300,300);
//Label the clock
15
String s="12";
int i=0;
while(i<12)
{
angle = Math.toRadians(30*(i-3));
x = 250+(int)
(Math.cos(angle)*135); y = 250+
(int)(Math.sin(angle)*135);
g.drawString(s,x,y);
i++;
s=String.valueOf(i);
}
//Draw the hours hand
g.setColor(Color.green);
angle = Math.toRadians((30*hour)-90);
x = 250+(int)(Math.cos(angle)*100);
y = 250+(int)(Math.sin(angle)*100);
g.drawLine(250,250,x,y);
//Draw the minutes hand
g.setColor(Color.red);
angle = Math.toRadians((6*minute)-90);
x = 250+(int)(Math.cos(angle)*115);
y = 250+(int)(Math.sin(angle)*115);
g.drawLine(250,250,x,y);
//Draw the seconds hand
g.setColor(Color.blue);
angle = Math.toRadians((6*second)-90);
x = 250+(int)(Math.cos(angle)*130);
y = 250+(int)(Math.sin(angle)*130);
g.drawLine(250,250,x,y);
}
}
/*
<applet code = Clock.class width=500 height=500>
</applet>
*/
16
6.0 Output of the Micro-Project:
17
7.0 Skill Developed:
Java applets are used to provide interactive features to web applications and can be
executed by browsers for many platforms.
Applets provide sound, graphics and animation in various forms and formats for
webpages.
They are used in games, gaming consoles, commercial websites, learning tools and
many more.
18