<?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; NullLayout</title>
	<atom:link href="http://ankit.co/tag/nulllayout/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>Custom Layout or null Layout</title>
		<link>http://ankit.co/tutorials/java-tutorials/layouts/custom-layout-or-null-layout?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=custom-layout-or-null-layout</link>
		<comments>http://ankit.co/tutorials/java-tutorials/layouts/custom-layout-or-null-layout#comments</comments>
		<pubDate>Sat, 12 Jan 2013 12:22:15 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Layouts]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[NullLayout]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=444</guid>
		<description><![CDATA[<p>&#8220;null&#8221; is a keyword of java. This tutorial is not about a any java class. And it&#8217;s also not about setting some layout. This is to remove the existing layout! And by removing the layout one can do the exact positioning of the components. We can remove the existing layout by calling a method: setLayout(null); [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/layouts/custom-layout-or-null-layout">Custom Layout or null Layout</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>&#8220;null&#8221; is a keyword of java. This tutorial is not about a any java class. And it&#8217;s also not about setting some layout. This is to remove the existing layout! And by removing the layout one can do the exact positioning of the components. </p>
<p>We can remove the existing layout by calling a method: setLayout(null); and then even if we try to components, that will not be displayed. To make component visible we need to invoke seBounds(x_cord, y_cord, width, height) method on all the components. </p>
<p><strong>Program:</strong></p>
<pre class="brush: java; title: ; notranslate">
import java.applet.*;
import java.awt.*;

public class NullLayoutDemo extends Applet
{
	Button b1, b2, b3;
	public void init()
	{
		setBackground(Color.green);
		setLayout(null);
		
		b1 = new Button(&quot;Button1&quot;);
		b2 = new Button(&quot;Button2&quot;);
		b3 = new Button(&quot;Button3&quot;);
		
		add(b1);
		add(b2);
		add(b3);
		
		b1.setBounds(50,100, 150, 50);
		b2.setBounds(50,200, 150, 50);
		b3.setBounds(50,300, 150, 50);
	}	
}
/*
&lt;applet code=&quot;NullLayoutDemo&quot; width=&quot;500&quot; height=&quot;500&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p><strong>Output:</strong><br />
<applet class="AppletBorder" code="NullLayoutDemo.class" width="500"  CODEBASE="../../../classes/" height="300"></applet></p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/layouts/custom-layout-or-null-layout">Custom Layout or null Layout</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/layouts/custom-layout-or-null-layout/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Color Chooser &#8211; multiple event handling</title>
		<link>http://ankit.co/tutorials/java-tutorials/event-handling/color-chooser-multiple-event-handling?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=color-chooser-multiple-event-handling</link>
		<comments>http://ankit.co/tutorials/java-tutorials/event-handling/color-chooser-multiple-event-handling#comments</comments>
		<pubDate>Fri, 11 Jan 2013 01:21:28 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Event Handling]]></category>
		<category><![CDATA[ActionListener]]></category>
		<category><![CDATA[Applet]]></category>
		<category><![CDATA[Listener]]></category>
		<category><![CDATA[NullLayout]]></category>
		<category><![CDATA[Thread]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=411</guid>
		<description><![CDATA[<p>This tutorial is on applying/handling multiple events in Applet based Application. What we are going to develop is a utility which selects the value of Red, Green and Blue in the range of 0 &#8211; 255 by using Scrollbar components. After setting up those three values, user can set the generated Color as Background. And [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/color-chooser-multiple-event-handling">Color Chooser &#8211; multiple event handling</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This tutorial is on applying/handling multiple events in Applet based Application. What we are going to develop is a utility which selects the value of Red, Green and Blue in the range of 0 &#8211; 255 by using Scrollbar components. After setting up those three values, user can set the generated Color as Background. And once the color is set, we gonna make it black in 10 seconds by a smooth change in Color intensity.</p>
<p><strong>If you are not clear with the program aim then scroll down and see the output and read again! </strong></p>
<p><strong>Declaring and Defining Array of components:</strong></p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;

public class ColorChooserApplet extends Applet 
{
	Button btn = new Button(&quot;Run&quot;);
	Label lbl[] = new Label[3];
	Scrollbar sc[] = new Scrollbar[3];
	TextField tf[] = new TextField[3];
	String[] slbl = {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;};
	public void init()
	{
		for(int i=0;i&lt;3;i++)
		{
			lbl[i] = new Label(slbl[i]);	
			sc[i] = new Scrollbar(Scrollbar.HORIZONTAL, 0, 20, 0, 275);
			tf[i] = new  TextField(&quot;0&quot;);
			add(lbl[i]);
			add(sc[i]);
			add(tf[i]);
		}
		add(btn);
	}
}

</pre>
<hr/>
<strong>Applying null layout:</strong><br />
Java based desktop applications support various Layouts. Default Layout of Applet application is FlowLayout in which components are attached one after another as per the direction set by use(default:center). Now in case we need exact positioning of components, We can remove the layout by calling a method setLayout(null) and add the components. After setting null layout if we try to add components, they will not be visible in output. To make it visible we have to call a method named setBounds(int x_cord, int y_cord, int component_width, int component_height) for each component object.</p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class ColorChooserApplet extends Applet 
{
	Button btn = new Button(&quot;Run&quot;);
	Label lbl[] = new Label[3];
	Scrollbar sc[] = new Scrollbar[3];
	TextField tf[] = new TextField[3];
	String[] slbl = {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;};
	public void init()
	{
		setLayout(null);

		for(int i=0;i&lt;3;i++)
		{
			lbl[i] = new Label(slbl[i]);	
			sc[i] = new Scrollbar(Scrollbar.HORIZONTAL, 0, 20, 0, 275);
			tf[i] = new  TextField(&quot;0&quot;);
			add(lbl[i]);
			add(sc[i]);
			add(tf[i]);
			lbl[i].setBounds(20,(75*i)+50, 50,30);
			sc[i].setBounds(70,(75*i)+50, 350,30);
			tf[i].setBounds(450,(75*i)+50, 50, 30);

		}
		add(btn);
		btn.setBounds(200,400,100,50);
	}
	
}

</pre>
<hr/>
<p><strong>Code to sync Scrollbars and TextFields:</strong><br />
In our application, When user moves Scrollbar the current value of scroll bar is to be displayed/updated in text field and vice versa.</p>
<pre class="brush: java; title: ; notranslate">
        public void adjustmentValueChanged(AdjustmentEvent e) 
        {
		for(int i=0;i&lt;3;i++)
		{
			tf[i].setText(sc[i].getValue()+&quot;&quot;);	
		}
			
        }
	 
        public void keyReleased(KeyEvent e) 
        {
		System.out.println(&quot;Release:&quot;+tf[0].getText());

		for(int i=0;i&lt;3;i++)
		{
			sc[i].setValue(Integer.parseInt(tf[i].getText()));	
		}
        }
</pre>
<hr/>
<p><strong>Full Program:</strong></p>
<pre class="brush: java; title: ; notranslate">
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class ColorChooserApplet extends Applet implements AdjustmentListener, KeyListener, ActionListener, Runnable
{
	int r=0,g=0,b=0;
	Thread t;
	Button btn = new Button(&quot;Run&quot;);
	Label lbl[] = new Label[3];
	Scrollbar sc[] = new Scrollbar[3];
	TextField tf[] = new TextField[3];
	String[] slbl = {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;};
	public void init()
	{
		setLayout(null);
		
		for(int i=0;i&lt;3;i++)
		{
			lbl[i] = new Label(slbl[i]);	
			sc[i] = new Scrollbar(Scrollbar.HORIZONTAL, 0, 20, 0, 275);
			tf[i] = new  TextField(&quot;0&quot;);
			add(lbl[i]);
			add(sc[i]);
			add(tf[i]);
			lbl[i].setBounds(20,(75*i)+50, 50,30);
			sc[i].setBounds(70,(75*i)+50, 350,30);
			tf[i].setBounds(450,(75*i)+50, 50, 30);
			
			sc[i].addAdjustmentListener(this);
			tf[i].addKeyListener(this);
		}
		add(btn);
		btn.setBounds(200,400,100,50);
		btn.addActionListener(this);
	}
	public void adjustmentValueChanged(AdjustmentEvent e) 
	{
		for(int i=0;i&lt;3;i++)
		{
			tf[i].setText(sc[i].getValue()+&quot;&quot;);	
		}
			
	}
	public void	keyPressed(KeyEvent e)
	{
		System.out.println(&quot;Pressed:&quot;+tf[0].getText());
		
	} 
    public void	keyReleased(KeyEvent e) 
	{
		System.out.println(&quot;Release:&quot;+tf[0].getText());

		for(int i=0;i&lt;3;i++)
		{
			sc[i].setValue(Integer.parseInt(tf[i].getText()));	
		}
	}
    public void	keyTyped(KeyEvent e)
	{
		System.out.println(&quot;Typed:&quot;+tf[0].getText());

	} 
	public void actionPerformed(ActionEvent e)
	{
		r = sc[0].getValue();
		g = sc[1].getValue();
		b = sc[2].getValue();
		Color clr = new Color(r,g,b);	
		setBackground(clr);
		t = new Thread(this);
		t.start();
	}
	
	public void run()
	{
		try
		{
			for(int i=0;i&lt;10;i++)
			{
				t.sleep(1000);
				r = r - sc[0].getValue()/10;
				g = g - sc[1].getValue()/10;
				b = b - sc[2].getValue()/10;
				Color clr = new Color(r,g,b);	
				setBackground(clr);			
			}
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
		
	}
}

/*
&lt;applet code=&quot;ColorChooserApplet&quot; width=&quot;550&quot; height=&quot;550&quot;&gt;&lt;/applet&gt;
*/
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/event-handling/color-chooser-multiple-event-handling">Color Chooser &#8211; multiple event handling</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/color-chooser-multiple-event-handling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
