Home Java Example Java Applet The Sample Banner Example in Java
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

The Sample Banner Example in Java

Advertisement
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.

Java - The Sample Banner Example in Java

     

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, 1150);
  }
}

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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

Ask Questions?    Discuss: The Sample Banner Example in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Kuldeep
December 5, 2012
Banner program showing error

Compiler shows no error, but while running it shows- Exception in Threadâ?? mainâ?? java.lang.NoSuchMethodError: main
DMCA.com