Introduction
Here, we will learn about making the banner in java applet. Simply the banner is used to
advertising for any institution, shops and any organizations. The
advertising can be done by the different - different ways but the main aim is to
popular our organization. For more popularity. But here, we will see what is a banner in the
computer manner. As we know that the displaying detailed information in the graphics
format on the page is known
as banner. In other words, the banner is a collection of graphics and texts. With the help of banner we easily
make to understand about the things.
In this program we will see how to display the banner in applet. This
example has been used to display the simple text rotation in a rectangular area
of the
appropriate applet to understand that what is the banner and how to use that. There are four types of
method have been used in this program these are explained below one by one
:
init() :
This is the init() method which is the first method of the life cycle of an
applet has been used to set the Background and Foreground colors of the banner.
start() :
This is the start()
method which is the
second method of the life cycle of an applet has been used to create and start a
thread.
run() :
This is the run() method which has been
used to set the time interval for the created thread. That means the rotation of text
to be rotate on how much time.
paint() :
And finally this is the paint() method
which has been used to draw the rectangle, set it's color and display the moving
text in the appropriate rectangle.
Here is the Java code:
import java.awt.*;
import java.applet.*;
public class SampleBanner extends Applet implements Runnable{
String str = "This is a simple Banner developed by Roseindia.net. ";
Thread t ;
boolean b;
public void init() {
setBackground(Color.gray);
setForeground(Color.yellow);
}
public void start() {
t = new Thread(this);
b = false;
t.start();
}
public void run () {
char ch;
for( ; ; ) {
try {
repaint();
Thread.sleep(250);
ch = str.charAt(0);
str = str.substring(1, str.length());
str = str + ch;
} catch(InterruptedException e) {}
}
}
public void paint(Graphics g) {
g.drawRect(1,1,300,150);
g.setColor(Color.yellow);
g.fillRect(1,1,300,150);
g.setColor(Color.red);
g.drawString(str, 1, 150);
}
}
|
Here is the HTML code:
<HTML>
<BODY>
<APPLET CODE =
"SampleBanner" WIDTH
= "500" HEIGHT
= "300"></APPLET>
</BODY>
</HTML>
|
Try online this example.
Download the Java Code

Current Comments
0 comments so far (post your own) View All Comments Latest 10 Comments: