<?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; Methodologies</title>
	<atom:link href="http://ankit.co/category/tutorials/java-tutorials/event-handling/event-handling-methodologies/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>Extending Adapter Class</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/extending-adapter-class?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extending-adapter-class</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/extending-adapter-class#comments</comments>
		<pubDate>Thu, 10 Jan 2013 11:12:35 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[Event Handling]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=369</guid>
		<description><![CDATA[<p>As we all know that: Java do not support multiple inheritance we cannot derive our Applet/Frame/JFrame based classes by any other class at the same time. In that case what can be done is: we can create a new class and that class will be derived from Adapter class. And our newly derived Adapter class [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/extending-adapter-class">Extending Adapter Class</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>As we all know that: Java do not support multiple inheritance we cannot derive our Applet/Frame/JFrame based classes by any other class at the same time. In that case what can be done is: we can create a new class and that class will be derived from Adapter class. And our newly derived Adapter class can be used as an argument of addXYZListener() method.</p>
<h4>Characteristics:</h4>
<ol>
<li>Components/Event Sources cannot be easily accessed from Listener methods. We must have object of base class(where we have components) in the Listener class(where we have Listener methods)</li>
<li>Event can be applied to a component by passing object of newly created adapter class which extends built in adapter class.</li>
<li>View and Controller part can be separated which is a good practice.</li>
<li>Not compulsory to define all the methods. No need to write Blank definition if not required.</li>
</ol>
<p>Code:</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo5 extends Applet
{
	Button btn;
	static Label lbl;
	public void init()
	{
		btn = new Button(&quot;Click Me!&quot;);
		lbl = new Label(&quot;          &quot;);
		add(btn);
		add(lbl);

		myAdapterClass myObj = new myAdapterClass();
		btn.addMouseListener(myObj);		
	}		 
 }
 
 class myAdapterClass extends MouseAdapter
 {
	public void mouseClicked(MouseEvent e)
	{
	 EventDemo5.lbl.setText(&quot;Clicked!&quot;);
	} 
  }
  
/*
&lt;applet code=&quot;EventDemo5&quot; width=&quot;500&quot; height=&quot;50&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/extending-adapter-class">Extending Adapter Class</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/event-handling/event-handling-methodologies/extending-adapter-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anonymous Adapter Class</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-adapter-class?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=anonymous-adapter-class</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-adapter-class#comments</comments>
		<pubDate>Thu, 10 Jan 2013 11:10:46 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[Event Handling]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=366</guid>
		<description><![CDATA[<p>An Adapter class is provided in java.awt.event package for those Listener interfaces which are having more than one method. Such as MouseAdapter, WindowAdapter, etc. Adapter class is derived from Listener interface and it provides blank definition of all the methods of derived listener. So that when we use Adapter class instead of Listener interface we [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-adapter-class">Anonymous Adapter Class</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>An Adapter class is provided in java.awt.event package for those Listener interfaces which are having more than one method. Such as MouseAdapter, WindowAdapter, etc. Adapter class is derived from Listener interface and it provides blank definition of all the methods of derived listener. So that when we use Adapter class instead of Listener interface we can skip writing any of the method which are unused. </p>
<h4>Characteristics:</h4>
<ol>
<li>Components/Event Sources can be easily accessed from Listener methods</li>
<li>To apply an event we have to pass anonymous object of Adapter class</li>
<li>Logic is to be written in complex inner methods</li>
<li>Not compulsory to define all the methods. No need to write Blank definition if not required.</li>
</ol>
<p>Code:</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo4 extends Applet
{
	Button btn;
	Label lbl;
	public void init()
	{
		btn = new Button(&quot;Click Me!&quot;);
		lbl = new Label(&quot;          &quot;);
		add(btn);
		add(lbl);

		btn.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				lbl.setText(&quot;Clicked&quot;);
			}
		});		
	}	
	 
 }
/*
&lt;applet code=&quot;EventDemo4&quot; width=&quot;500&quot; height=&quot;50&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-adapter-class">Anonymous Adapter Class</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/event-handling/event-handling-methodologies/anonymous-adapter-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anonymous Listener Interface</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-listener-interface?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=anonymous-listener-interface</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-listener-interface#comments</comments>
		<pubDate>Thu, 10 Jan 2013 11:08:27 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[Event Handling]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=362</guid>
		<description><![CDATA[<p>Anonymous Listener can be passed in the argument of addXYZListner() method. This anonymous class must consist of all the method. Characteristics: Components/Event Sources can be easily accessed from Listener methods To apply an event we have to pass anonymous object of Listener Interface Logic is to be written in complex inner methods All the methods [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-listener-interface">Anonymous Listener Interface</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Anonymous Listener can be passed in the argument of addXYZListner() method. This anonymous class must consist of all the method. </p>
<h4>Characteristics:</h4>
<ol>
<li>Components/Event Sources can be easily accessed from Listener methods</li>
<li>To apply an event we have to pass anonymous object of Listener Interface</li>
<li>Logic is to be written in complex inner methods</li>
<li>All the methods must be defined. Blank definition is to be given even if we don&#8217;t want to use it.</li>
</ol>
<p>Code:</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo3 extends Applet
{
	Button btn;
	Label lbl;
	public void init()
	{
		btn = new Button(&quot;Click Me!&quot;);
		lbl = new Label(&quot;          &quot;);
		add(btn);
		add(lbl);

		btn.addMouseListener(new MouseListener()
		{
			public void mouseClicked(MouseEvent e){ lbl.setText(&quot;Clicked!&quot;); } 
			public void mouseEntered(MouseEvent e){}
			public void mouseExited(MouseEvent e){}
			public void mousePressed(MouseEvent e){} 
			public void mouseReleased(MouseEvent e){}			
		});		
	}	
	 
 }
/*
&lt;applet code=&quot;EventDemo3&quot; width=&quot;500&quot; height=&quot;50&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/anonymous-listener-interface">Anonymous Listener Interface</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/event-handling/event-handling-methodologies/anonymous-listener-interface/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Listener and Event Source in the different class</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-different-class?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=event-listener-and-event-source-in-the-different-class</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-different-class#comments</comments>
		<pubDate>Thu, 10 Jan 2013 11:05:18 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[Event Handling]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=359</guid>
		<description><![CDATA[<p>Event Listener is implemented in the different class than where we have components. In this case to apply the listener, we have to pass the object of that class. so that whenever event occurs JRE can call the method of Listener. Characteristics: Components/Event Sources cannot be easily accessed from Listener methods. We must have object [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-different-class">Event Listener and Event Source in the different class</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Event Listener is implemented in the different class than where we have components. In this case to apply the listener, we have to pass the object of that class. so that whenever event occurs JRE can call the method of Listener.</p>
<h3>Characteristics:</h3>
<ol>
<li>Components/Event Sources cannot be easily accessed from Listener methods. We must have object of base class(where we have components) in the Listener class(where we have Listener methods)</li>
<li>Event can be applied to a component by passing object of newly created Listener class.</li>
<li>View and Controller part can be separated which is a good practice.</li>
<li>All the methods must be defined in our newly created class. Blank definition is to be given even if we don&#8217;t want to use it.</li>
</ol>
<p>Code:</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo2 extends Applet
{
	Button btn;
	static Label lbl;
	public void init()
	{
		btn = new Button(&quot;Click Me!&quot;);
		lbl = new Label(&quot;          &quot;);
		add(btn);
		add(lbl);
		myListenerClass myobj = new myListenerClass();
		btn.addMouseListener(myobj);
	}	
	
	
 }
 
  class myListenerClass implements MouseListener
  {
	public void mouseClicked(MouseEvent e)
	{
	 EventDemo2.lbl.setText(&quot;Clicked!&quot;);
	} 
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
	public void mousePressed(MouseEvent e){} 
	public void mouseReleased(MouseEvent e){} 
  }
/*
&lt;applet code=&quot;EventDemo2&quot; width=&quot;500&quot; height=&quot;50&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-different-class">Event Listener and Event Source in the different class</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/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-different-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Listener and Event Source in the same class</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-same-class?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=event-listener-and-event-source-in-the-same-class</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-same-class#comments</comments>
		<pubDate>Thu, 10 Jan 2013 11:02:19 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[Event Handling]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=355</guid>
		<description><![CDATA[<p>This is same as what we did in previous tutorial on &#8220;ActionListener – Click event handling&#8220;. Event Listener is implemented in the class where we have components like Button, Label, etc. In this implementation, we have to add all the methods of Listener in the same class. Characteristics: Components/Event Sources can be easily accessed from [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-same-class">Event Listener and Event Source in the same class</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is same as what we did in previous tutorial on &#8220;<a href="tutorials/java-tutorials/event-handling/actionlistener-click-event-handling" title="ActionListener – Click event handling">ActionListener – Click event handling</a>&#8220;.<br />
Event Listener is implemented in the class where we have components like Button, Label, etc. In this implementation, we have to add all the methods of Listener in the same class.</p>
<h3>Characteristics:</h3>
<ol>
<li>Components/Event Sources can be easily accessed from Listener methods</li>
<li>Event can be applied to any component by passing current object(this). No need of creating other object.</li>
<li>View as well as Logic is combined in single class which is a bad practice.</li>
<li>All the methods must be defined. Blank definition is to be given even if we don&#8217;t want to use it.</li>
</ol>
<p>Code:</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class EventDemo1 extends Applet implements MouseListener
{
	Button btn;
	Label lbl;
	public void init()
	{
		btn = new Button(&quot;Click Me!&quot;);
		lbl = new Label(&quot;          &quot;);
		add(btn);
		add(lbl);
		btn.addMouseListener(this);
	}	
	public void mouseClicked(MouseEvent e)
	{
	 lbl.setText(&quot;Clicked!&quot;);
	} 
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
	public void mousePressed(MouseEvent e){} 
	public void mouseReleased(MouseEvent e){} 
 }
/*
&lt;applet code=&quot;EventDemo1&quot; width=&quot;500&quot; height=&quot;50&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-same-class">Event Listener and Event Source in the same class</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/event-handling/event-handling-methodologies/event-listener-and-event-source-in-the-same-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
