The Sample Banner Example in Java

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 Sample Banner Example in Java

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 Sample Banner Example in Java

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

Tutorials

  1. What is an Applet
  2. The Life cycle of An Applet
  3. Java Applet - Creating First Applet Example
  4. Java - Drawing Shapes Example in java
  5. Java - Drawing Shapes Example using color in java
  6. Java - Event Listeners Example in Java Applet
  7. Applet - Passing Parameter in Java Applet
  8. Opening a URL from an Applet
  9. Java - Opening a url in new window from an applet
  10. Applet is not Working
  11. Display image in the applet
  12. Applet Write Files Example
  13. Play Audio in Java Applet
  14. Security Issues with the Applet
  15. Swing Applet Example in java
  16. The Sample Banner Example in Java
  17. Clock Applet in Java
  18. HTML Document Creation
  19. Tag Parameters: The Tag
  20. The APPLET Tag in Detail
  21. Java and HTML: The Basics
  22. What Exactly is HTML?
  23. Welcome to the Internet
  24. java.applet package examples
  25. java.applet package examples
  26. What is an Applet - Java Applet Tutorial
  27. Java - Read file Applet
  28. Applet versus Application
  29. Tag Parameters: The Tag
  30. Java - Opening a url in new window from an applet
  31. Java - Opening a URL from an Applet
  32. Applet Tag Parameters,Applet Tag in HTML
  33. Applets in Java
  34. What is Applet in Java?
  35. What is Applet in Java with Example?