<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ankit Virparia &#187; Banner</title>
	<atom:link href="http://ankit.co/tag/banner/feed" rel="self" type="application/rss+xml" />
	<link>http://ankit.co</link>
	<description>A Programmer, Designer and Trainer</description>
	<lastBuildDate>Sun, 11 May 2014 04:15:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Banner Applet</title>
		<link>http://ankit.co/tutorials/java-tutorials/applet/banner-applet?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=banner-applet</link>
		<comments>http://ankit.co/tutorials/java-tutorials/applet/banner-applet#comments</comments>
		<pubDate>Sun, 06 Jan 2013 04:02:24 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Applet]]></category>
		<category><![CDATA[Banner]]></category>
		<category><![CDATA[Thread + Applet]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=173</guid>
		<description><![CDATA[<p>Banner Applet is an applet application which continuously rotates the text chars after given time interval. For Example, This is Demo. his is Demo.T is is Demo.Th &#8230; How to write program for this? We need applet first. Will follow the applet life cycle We want to draw a String on applet area. Which can [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/applet/banner-applet">Banner Applet</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Banner Applet is an applet application which continuously rotates the text chars after given time interval. </p>
<p><strong>For Example,</strong></p>
<p>This is Demo.<br />
his is Demo.T<br />
is is Demo.Th<br />
&#8230;</p>
<h2>How to write program for this?</h2>
<ol>
<li>We need applet first. Will follow the applet life cycle
<pre class="brush: java; title: ; notranslate">
import java.applet.*;
import java.awt.*;

public class bannerDemo extends Applet
{
	public void init()
	{
	}
	public void paint(Graphics g)
	{
	}		
}
/*
&lt;applet code=&quot;bannerDemo&quot; width=&quot;500&quot; height=&quot;150&quot;&gt;&lt;/applet&gt;
*/
</pre>
</li>
<li>We want to draw a String on applet area. Which can be done by calling drawString() method of Graphics class inside paint() method.
<pre class="brush: java; title: ; notranslate">
	public void paint(Graphics g)
	{
		Font f = new Font(&quot;Arial&quot;,Font.BOLD,36);
		g.setFont(f);
		g.drawString(&quot;Ankit Virparia (ankit.co)&quot;,50,75);
	}	
</pre>
</li>
<li>We want continuous change in the text which we have printed so, Will go for multithreading.
<pre class="brush: java; title: ; notranslate">
public class bannerDemo extends Applet implements Runnable
{
	Thread t;
        public void run()
	{}
}
</pre>
</li>
<li>Here one extra thread will be given a responsibility to update the text given (which is stored in a global variable &#8211; I mean common between paint() and run() methods)
<pre class="brush: java; title: ; notranslate">
public class bannerDemo extends Applet implements Runnable
{
	Thread t;
	String msg = &quot;Ankit Virparia (ankit.co)&quot;;
	
	public void run()
	{
		try
		{
			while(true)
			{
				t.sleep(1000);
				char c = msg.charAt(0);
				String tmp = msg.substring(1,msg.length());
				msg = tmp + c;
				repaint();
			}
		}
		catch(Exception e)
		{
			System.out.println(e);	
		}
	}
		
	public void paint(Graphics g)
	{
		Font f = new Font(&quot;Arial&quot;,Font.BOLD,36);
		g.setFont(f);
		g.drawString(msg,50,75);
	}	
	
}
</pre>
</li>
<li>We need to start the thread in the beginning. Which can be written in init() method.
<pre class="brush: java; title: ; notranslate">
	Thread t;
	public void init()
	{
		t = new Thread(this);
		t.start();
	}
</pre>
</li>
<li>paint() is invoked only when a user does GUI related change. But here in our case we want to invoke paint() at the interval of 1 second.
<pre class="brush: java; title: ; notranslate">
</pre>
</li>
<li>We are ready to go!</li>
</ol>
<hr/>
<h3>Program for Banner Applet</h3>
<p><strong>File Name:</strong>bannerDemo.java</p>
<pre class="brush: java; title: ; notranslate">
import java.applet.*;
import java.awt.*;

public class bannerDemo extends Applet implements Runnable
{
	Thread t;
	String msg = &quot;Ankit Virparia (ankit.co)&quot;;
	public void init()
	{
		t = new Thread(this);
		t.start();
	}
	
	public void run()
	{
		try
		{
			while(true)
			{
				t.sleep(1000);
				char c = msg.charAt(0);
				String tmp = msg.substring(1,msg.length());
				msg = tmp + c;
				repaint();
			}
		}
		catch(Exception e)
		{
			System.out.println(e);	
		}
	}
		
	public void paint(Graphics g)
	{
		Font f = new Font(&quot;Arial&quot;,Font.BOLD,36);
		g.setFont(f);
		g.drawString(msg,50,75);
	}	
	
}

/*
&lt;applet code=&quot;bannerDemo&quot; width=&quot;500&quot; height=&quot;150&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p><img src="http://ankit.co/wp-content/uploads/2013/01/p5.jpg" alt="p5" width="500" height="104" class="aligncenter size-full wp-image-3542" /></p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/applet/banner-applet">Banner Applet</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/applet/banner-applet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
