<?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>Java Interview Questions &#187; AWT Question</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/awt-question/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What is Event Delegation Model</title>
		<link>http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/</link>
		<comments>http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:54:51 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Event Delegation Model]]></category>
		<category><![CDATA[event delegation model]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=463</guid>
		<description><![CDATA[Event Delegation Model Wen the user generates an event, the component delegates(handovers) that event to a listner. Listener is an interface that contains same methods, so Listener will delegate the event to one of the methods, finally the method is executed and the event is handled, this is called event delegation model. Event delegation model [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>Event Delegation Model</strong></span></p>
<p>Wen the user generates an event, the component delegates(handovers) that event to a listner.</p>
<p>Listener is an interface that contains same methods, so Listener will delegate the event to one of the methods, finally the method is executed and the event is handled, this is called <strong><em>event delegation model.</em></strong></p>
<p>Event delegation model is used to provide action for awt Components</p>
<p>In event delegation model we should flow the steps.</p>
<p><strong> &#8211; - &#8211; &gt;</strong> Add a (suitable ) Listener to the component</p>
<p><strong> &#8211; - &#8211; &gt; </strong>Implement all the methods of the Listener</p>
<p><strong> &#8211; - &#8211; &gt; </strong>When the user interacts with the components listener call&#8217;s the methods and the method will handle the event.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-id/" title="Define Session ID">Define Session ID</a> (0)</li><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-jsp-directives/" title="Explain Jsp Directives">Explain Jsp Directives</a> (0)</li><li>July 7, 2008 -- <a href="http://www.bestjavainterviewquestions.com/ejb-interview-questions/" title="EJB INTERVIEW QUESTIONS">EJB INTERVIEW QUESTIONS</a> (1)</li><li>April 6, 2009 -- <a href="http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/" title="Exception Handling and their uses">Exception Handling and their uses</a> (2)</li><li>June 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/awt-interview-questions-2/" title="AWT Interview Questions">AWT Interview Questions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a Frame Non-Resizable in Java</title>
		<link>http://www.bestjavainterviewquestions.com/making-a-frame-non-resizable-in-java/</link>
		<comments>http://www.bestjavainterviewquestions.com/making-a-frame-non-resizable-in-java/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 18:17:31 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[java.awt.Frame]]></category>
		<category><![CDATA[Awt Frame class]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=447</guid>
		<description><![CDATA[yes u can make the applet program resizable. In java  there is a method called setResizable method. This method which is responsible for modifying the size of the window on  your applet/awt program   . In your program, Assume that you have taken a boolean value false for method setResizable then the frame will be non-resizable [...]]]></description>
			<content:encoded><![CDATA[<p><strong>yes u can make the applet program resizable.</strong></p>
<p>In java  there is a method called setResizable method. This method which is responsible for modifying the size of the window on  your applet/awt program   .<br />
In your program, Assume that you have taken a boolean value false for method setResizable then the frame will be non-resizable otherwise frame will be resizable, The setResizable method is the method of Frame class.</p>
<p>Here is the few related methods views of the Frame Class Supported by the api of jdk1.5</p>
<hr /><strong><br />
SW_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int SW_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.SW_RESIZE_CURSOR.</p>
<hr /><strong><br />
SE_RESIZE_CURSOR</strong><br />
<em><br />
@Deprecated</em><br />
public static final int SE_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.SE_RESIZE_CURSOR.</p>
<hr /><strong>NW_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int NW_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.NW_RESIZE_CURSOR.</p>
<hr /><strong>NE_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int NE_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.NE_RESIZE_CURSOR.</p>
<hr /><strong>N_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int N_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.N_RESIZE_CURSOR.</p>
<hr /><strong><br />
S_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int S_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.S_RESIZE_CURSOR.</p>
<hr /><strong>W_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int W_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.W_RESIZE_CURSOR.</p>
<hr /><strong>E_RESIZE_CURSOR</strong></p>
<p><em>@Deprecated</em><br />
public static final int E_RESIZE_CURSOR</p>
<p>Deprecated. replaced by Cursor.E_RESIZE_CURSOR.</p>
<hr /><strong><br />
isResizable</strong></p>
<p>public boolean isResizable()</p>
<p>Indicates whether this frame is resizable by the user. By default, all frames are initially resizable.</p>
<p>Returns:<br />
true if the user can resize this frame; false otherwise.</p>
<hr /><strong>setResizable</strong></p>
<p>public void setResizable(boolean resizable)</p>
<p>Sets whether this frame is resizable by the user.</p>
<p>Parameters:<br />
resizable &#8211; true if this frame is resizable; false otherwise.</p>
<hr /><strong>setState</strong></p>
<p>public void setState(int state)</p>
<p>Sets the state of this frame (obsolete).</p>
<p>In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.</p>
<p>For compatibility with old programs this method still accepts Frame.NORMAL and Frame.ICONIFIED but it only changes the iconic state of the frame, other aspects of frame state are not affected by this method.</p>
<p>Parameters:<br />
state &#8211; either Frame.NORMAL or Frame.ICONIFIED.<br />
See Also:<br />
getState(), setExtendedState(int)</p>
<hr /><strong>setExtendedState</strong></p>
<p>public void setExtendedState(int state)</p>
<p>Sets the state of this frame. The state is represented as a bitwise mask.</p>
<p>* NORMAL<br />
Indicates that no state bits are set.<br />
* ICONIFIED<br />
* MAXIMIZED_HORIZ<br />
* MAXIMIZED_VERT<br />
* MAXIMIZED_BOTH<br />
Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT.</p>
<p>Note that if the state is not supported on a given platform, nothing will happen. The application may determine if a specific state is available via the java.awt.Toolkit#isFrameStateSupported(int state) method.</p>
<p>Parameters:<br />
state &#8211; a bitwise mask of frame state constants<br />
Since:<br />
1.4<br />
See Also:<br />
getExtendedState(), Toolkit.isFrameStateSupported(int)</p>
<hr /><strong><br />
getState</strong></p>
<p>public int getState()</p>
<p>Gets the state of this frame (obsolete).</p>
<p>In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.</p>
<p>For compatibility with old programs this method still returns Frame.NORMAL and Frame.ICONIFIED but it only reports the iconic state of the frame, other aspects of frame state are not reported by this method.</p>
<p>Returns:<br />
Frame.NORMAL or Frame.ICONIFIED.<br />
See Also:<br />
setState(int), getExtendedState()</p>
<hr /><strong><br />
getExtendedState</strong></p>
<p>public int getExtendedState()</p>
<p>Gets the state of this frame. The state is represented as a bitwise mask.</p>
<p>* NORMAL<br />
Indicates that no state bits are set.<br />
* ICONIFIED<br />
* MAXIMIZED_HORIZ<br />
* MAXIMIZED_VERT<br />
* MAXIMIZED_BOTH<br />
Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT.</p>
<p>Returns:<br />
a bitwise mask of frame state constants<br />
Since:<br />
1.4<br />
See Also:<br />
setExtendedState(int)<br />
if u want overview all the api of Frame follow the link below</p>
<p><a href="http://computerpreferedcourses.blogspot.com/2008/11/api-of-frame-class.html" target="_blank">Api of Frame</a></p>
<p><strong><em>illustrating an example on java.awt.Frame class</em></strong></p>
<p><strong><em>import java.awt.*;<br />
import java.awt.event.*;</em></strong></p>
<p><strong><em>public class AwtFrameNonResizable{<br />
public static void main(String[] args){<br />
Frame frame = new Frame(&#8220;Non Resizable Frame&#8221;);<br />
Image icon = Toolkit.getDefaultToolkit().getImage(&#8220;your pic.gif&#8221;);<br />
frame.setIconImage(icon);<br />
Label lbl = new Label(&#8220;The View of the Image. &#8220;,Label.CENTER);<br />
frame.add(lbl);<br />
frame.setResizable(false);<br />
frame.setSize(400,400);<br />
frame.setVisible(true);<br />
frame.addWindowListener(new WindowAdapter(){<br />
public void windowClosing(WindowEvent we){<br />
Frame frame = (Frame)we.getSource();<br />
frame.dispose();<br />
}<br />
});<br />
}<br />
}</em></strong></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>October 5, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-executequery-method/" title="Explain executeQuery Method">Explain executeQuery Method</a> (0)</li><li>October 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-jsp/" title="Define JSP">Define JSP</a> (2)</li><li>July 7, 2008 -- <a href="http://www.bestjavainterviewquestions.com/servlet-important-questions/" title="Servlet Important Questions">Servlet Important Questions</a> (0)</li><li>February 9, 2009 -- <a href="http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/" title="Uploading Excel File  Using Jsp">Uploading Excel File  Using Jsp</a> (0)</li><li>October 27, 2008 -- <a href="http://www.bestjavainterviewquestions.com/benefits-of-connection-pooling/" title="Benefits of Connection Pooling">Benefits of Connection Pooling</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/making-a-frame-non-resizable-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWT Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/awt-interview-questions-3/</link>
		<comments>http://www.bestjavainterviewquestions.com/awt-interview-questions-3/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 17:32:36 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[AWT Question]]></category>
		<category><![CDATA[Abstract Window ToolKit questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=18</guid>
		<description><![CDATA[Q) Why do I get this when using JDK 1.1 under X Windows? java.lang.NullPointerException at sun.awt.motif.MFramePeer.&#60;init&#62;(MFramePeer.java:59) at sun.awt.motif.MToolkit.createFrame(MToolkit.java:153) at java.awt.Frame.addNotify(Frame.java) at java.awt.Window.pack(Window.java) A. There&#8217;s a missing font on your system. Move font.properties from the &#8220;lib&#8221; subdirectory aside to font.properties.bak Then it won&#8217;t look for the font and fail to find it. The problem occurs because [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) Why do I get this when using JDK 1.1 under X Windows? java.lang.NullPointerException at sun.awt.motif.MFramePeer.&lt;init&gt;(MFramePeer.java:59) at sun.awt.motif.MToolkit.createFrame(MToolkit.java:153) at java.awt.Frame.addNotify(Frame.java) at java.awt.Window.pack(Window.java)</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. There&#8217;s a missing font on your system. Move font.properties from the &#8220;lib&#8221; subdirectory aside to font.properties.bak Then it won&#8217;t look for the font and fail to find it.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">The problem occurs because the Motif AWT libraries use the Font &#8220;plain Dialog 12 point&#8221; as a fall-back default font. Unfortunately, when using a remote X server sometimes this font isn&#8217;t available. On an X-terminal, the diagnostic may be slightly different, a segv % appletviewer HelloWorldApplet.html SIGSEGV 11*segmentation violation si_signo [11]: SIGSEGV 11* segmentation violation si_errno [0]: Error 0 si_code [1]: SEGV_ACCERR [addr: 0x14]</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">To determine which fonts you have, issue a command such as xlsfonts &gt; ~/fonts.txt</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Then pick through the long list of fonts to determine which ones you want to use. The xfd program will let you look at a font: xfd -fn &#8220;your font name here&#8221; &amp;</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) Why is GridBagLayout so hard to use?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. GridBagLayout was contributed to Javasoft by a programmer who wanted to support the Java effort. It was intended as a proof that the AWT offered enough features for programmers to write their own layout managers. It wasn&#8217;t designed with human factors and ease of use in mind. If it bothers you (it bothers me) then just don&#8217;t use it. Create your GUI on several panels and use the other layout managers as appropriate to get the exact effect you want. The official story from the project leader of the AWT project, as explained to the Mountain View Java Users&#8217; Group on </span><span style="font-size: 11pt;">Dec 4 1996</span><span style="font-size: 11pt;">, is: &#8220;The case has been made and is now accepted that GridBagLayout is too hard to use for what it offers. GBL will continue to be supported, and something better and simpler will eventually be provided as well. This &#8220;better GBL&#8221; can be used instead of GBL.&#8221;</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Bottom line: nobody has to waste any effort on GBL, there are better alternatives available now, and it will be replaced by the SwingSet &#8220;SpringLayout&#8221; Springs &amp; Struts style layout manager to be introduced as part of the Java Foundation Classes with JDK 1.2.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do you change the font type and size of text in a TextArea?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. myTextArea.setFont(new Font(&#8220;NAME&#8221;, &lt;STYLE&gt;, &lt;SIZE&gt;)); where NAME is the name of the font (eg Dialog or TimesRoman). &lt;STYLE&gt; is Font.PLAIN, Font.ITALIC, Font.BOLD or any additive combination (e.g. Font.ITALIC+Font.BOLD). &lt;SIZE&gt; is the size of the font, e.g. 12.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">e.g. new Font(&#8220;TimesRoman&#8221;, Font.PLAIN, 18);</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) MyClass works fine except when I try to set a particular font. I just can&#8217;t seem to get it to work in Win95, but I can get it to work on a MacOS and Unix.</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. You probably specified a font name that isn&#8217;t available under your Win95; this is one of those cross-platform differences that can bite you if you over-specify for one platform, like specifying &#8220;Ariel&#8221; as a font and expecting it to work on something other than Windows. On both Windows 95 and Solaris 2.6, these fonts Dialog SansSerif Serif Monospaced Helvetica TimesRoman Courier DialogInput ZapfDingbats are revealed by this code:</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">import java.awt.*;</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">class foonly</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">{</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">static public void main(String s[])</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">{</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">String n[] = new Frame().getToolkit().getFontList();</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">for (int i=0; i&lt;n.length; i++)</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">System.out.println(n[i]);</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">System.exit(0); </span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">}</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">}</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">In other words, You can get a String array of the names of the fonts by String[] fonts = Toolkit.getDefaultToolkit().getFontList()</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) Is it possible to draw a polygon or a line more than 1 pixel wide?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. JDK 1.1.1 doesn&#8217;t have support for this. The standard workaround for drawing a thick line is to draw a filled polygon. The standard workaround for drawing a thick polygon is to draw several polygons. There is a useful class at http://www.apl.jhu.edu/~hall/java/GraphicsUtil.html</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">It extends the drawxxx and fillxxx methods of java.awt.Graphics. It adds a Line Width argument to most of the drawxxx methods, a Color argument to most of the drawxxx and fillxxx methods, and a Font argument to draw String and drawChars.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) I use add(Component) to add Components to the Container. Is there any way to explicitly set the z-order of these Components?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. JDK 1.0 has no way to explicitly set the z-order of components. You can try it heuristically, based on the browser you&#8217;re using, or you can use CardLayoutManager to ensure the panel you want is at the front.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">IN JDK 1.1 the z-order of components can be controlled by using the the method add(Component comp, int index). By default, components are added 0 to N. The method paint of class Container paints its visible components from N to 0.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) When I call repaint() repeatedly, half my requests get lost and don&#8217;t appear on the screen. Why is this?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. repaint() just tells the AWT that you&#8217;d like a paint to happen. AWT will fold several adjacent repaint requests into one, so that only the most current paint is done. One possible workaround might be to use a clip rectangle and only paint the different areas that have changed.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) What is the difference between Component&#8217;s setForeground(Color c) and Graphics&#8217;s setColor(Color c) ?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. First of all, these methods do the same thing: set the foreground color to the value of the parameter. The difference lies in where you use them. There is also a Component.setBackground that will set the background color.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">If you are in a constructor or an event handler (e.g. &#8220;click here to turn the canvas blue&#8221;) you have a Component and should use the setForeground() method. If you are in a paint() method, that takes a Graphics context as its argument so you will typically use g.setColor(c).</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Unlike a Component, a Graphics object doesn&#8217;t have a background color and a foreground color that you can change independently. A Graphics object arrives in the color(s) inherited from the drawing surface. From then on, any rendering (drawLine(), drawRect(), fillOval(), etc.) will be done in the setColor() color. Because they do different things, the Component and Graphics methods have different names.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) When I start a mouse drag inside a Component, and go outside the Component, still dragging, the mouse events still get sent to the Component, even though I am outside it. Is this a bug?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. No, it is the specified behavior. The java API documentation says: &#8220;&#8230; Mouse drag events continue to get sent to this component even when the mouse has left the bounds of the component. The drag events continue until a mouse up event occurs. &#8230;&#8221;</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">It is done for the convenience and ease of the application programmer. It allows you to handle all drags from the place of origin. If you don&#8217;t want this, simply look at the coordinates of the mouseDrag Event, and if they are outside the Component, ignore them.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) What&#8217;s all this about subclassing Canvas and overriding paint() ? Can&#8217;t I just do a getGraphics() for a component, and draw directly on that?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. You can do that, and it might work up to a point (or it might not). A problem arises when the window system wants to refresh that component</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">e.g. because it has been partially obscured and is now revealed. It calls paint(), and that has no knowledge of the other g.drawing() you have done.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) But couldn&#8217;t the AWT just remember what has been drawn to a Graphics context, and replicate that instead of calling paint()?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. It could, but that is not how it works. In practice it is a lot simpler to be able to look at the paint method, and see explicitly all the things that will be done to draw that component. Bottom line: use paint(), not g=getGraphics(); g.drawString( &#8230;</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How can I get the dimensions and resolution of the screen?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. java.awt.Toolkit.getDefaultToolkit().getScreenSize() java.awt.Toolkit.getDefaultToolkit().getScreenResolution() Screen resolution is in dots-per-inch.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Take a look in the Toolkit class for other useful methods.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Toolkit.getDefaultToolkit().getColorModel().getPixelSize() gets you the color model in terms of bits per pixel.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Math.pow(2,Toolkit.getDefaultToolkit().getColorModel().getPixelSize()) gets you the color model in terms of number of colors. Or use this: 1 &lt;&lt; Toolkit.getDefaultToolkit().getColorModel().getPixelSize()</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">That does a shift left to calculate the power of two.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do I allow for the size of the title bar and border when I draw a Frame?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. Use MyFrame.getInsets(). This returns a java.awt.Insets object which has four ints: top, left, bottom, right, giving the number of pixels each of those margins are inset from the top. You can use these value to adjust the Dimension object returned by component.getSize().</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) When I run the Swing demo on Win95 I get an error &#8220;Out of environment space&#8221;</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. That&#8217;s because you don&#8217;t have enough space for your DOS environment. You can fix this with: Right click your MS-DOS Prompt icon or window and choose Properties. Choose &#8220;Memory&#8221; and on &#8220;Initial Environment&#8221; choose 4096 instead of &#8220;auto&#8221;. Run Swing again, you&#8217;ll be OK.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do I resize a List? I had a List defined as List tlist = new List(10); but the Strings in the list were 80 characters long and only the first 15 were being shown. I was not able to resize the List to display the contents without using the scroll bar.</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. A List cannot be resized in a constructor, so add the following to the Applet (or wherever) public void paint (Graphics g) { tlist.setSize(200,200); } Then before showing panel/frame with the List: tlist.resize(400,400);</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How can my program tell when a window is resized?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. Override the setBounds() method of Component to do what you want. Of course, have it call super.setBounds() as well. Note that setBounds() replaces reshape() which is deprecated.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">Note the new APIs call the deprecated APIs instead of the other way round. For example, Component.setBounds calls Component.reshape, instead of reshape calling setBounds.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do I get back to a normal echo after I have used TextField.setEchoChar(&#8216;*&#8217;);</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. TextField.setEchoChar(&#8216;\0&#8242;) works on most Windows based browsers&#8230; but for most other platforms (ie: Netscape under UNIX), it just locks up the textfield.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;">There is only one good solution, and that is to make two TextFields on top of each other, one normal, and one with .setEchoChar(&#8216;*&#8217;), and switch between them.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do I clear the contents of a TextArea?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. Set it to a null String with this: area.setText(&#8220;&#8221;);</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) What are those preferredSize() and minimumSize() methods in Component?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. Those methods allow a LayoutManager to calculate the preferred and minimum sizes of the Components it is arranging. You can control the values that the LayoutManager gets by creating subclasses of the Components you are using and overriding these methods.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How can I force a synchronization of the graphics state, e.g. of a cursor change, or an animation frame to be rendered?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. This is done by the sync() method in the toolkit. So just use: AnyComponent.getToolkit().sync();</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How do I plot a single pixel to the screen?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. Use g.drawLine(x1,y1,x1,y1) to draw a line one pixel in length.</span></p>
<p class="MsoNormal"><strong><span style="font-size: 11pt; color: black;">Q) How can I tab between components?</span></strong></p>
<p class="MsoNormal"><span style="font-size: 11pt;">A. In JDK 1.0, you have to read the key press, and program it explicitly. JDK 1.1 supports tab and shift-tab (previous field) automatically. The tab order is the order that the components were added to the container.</span></p>
<p class="MsoNormal">
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 30, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-thread-safe-jsp-page-and-there-advantages/" title="Explain Thread-Safe JSP page and there advantages">Explain Thread-Safe JSP page and there advantages</a> (0)</li><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-jsp-expressions/" title="Explain Jsp Expressions">Explain Jsp Expressions</a> (0)</li><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/" title="Explain Stream Tokenizer">Explain Stream Tokenizer</a> (0)</li><li>September 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/naming-conventions-in-java/" title="Naming Conventions in Java">Naming Conventions in Java</a> (0)</li><li>August 10, 2008 -- <a href="http://www.bestjavainterviewquestions.com/example-programs-of-lifecycle-of-servlets/" title="Example programs of lifecycle of servlets">Example programs of lifecycle of servlets</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/awt-interview-questions-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWT Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/awt-interview-questions-2/</link>
		<comments>http://www.bestjavainterviewquestions.com/awt-interview-questions-2/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 16:52:43 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[AWT Question]]></category>
		<category><![CDATA[awt tips for interview]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=17</guid>
		<description><![CDATA[Q) How would you set the color of a graphics context called g to cyan? a) g.setColor(Color.cyan); b) g.setCurrentColor(cyan); c) g.setColor(&#8220;Color.cyan&#8221;); c) g.setColor(&#8220;cyan’); e) g.setColor(new Color(cyan)); Ans : a. Q) The code below draws a line. What color is the line? g.setColor(Color.red.green.yellow.red.cyan); g.drawLine(0, 0, 100,100); a) Red b) Green c) Yellow d) Cyan e) Black [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) How would you set the color of a graphics context called g to cyan?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) g.setColor(Color.cyan); b) g.setCurrentColor(cyan); </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) g.setColor(&#8220;Color.cyan&#8221;); c) g.setColor(&#8220;cyan’); </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">e) g.setColor(new Color(cyan));</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) The code below draws a line. What color is the line?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.setColor(Color.red.green.yellow.red.cyan);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.drawLine(0, 0, 100,100);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) Red b) Green c) Yellow d) Cyan e) Black</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : d.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What does the following code draw?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.setColor(Color.black); g.drawLine(10, 10, 10, 50);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.setColor(Color.RED); g.drawRect(100, 100, 150, 150);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) A red vertical line that is 40 pixels long and a red square with sides of 150 pixels </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">b) A black vertical line that is 40 pixels long and a red square with sides of 150 pixels </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) A black vertical line that is 50 pixels long and a red square with sides of 150 pixels </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">d) A red vertical line that is 50 pixels long and a red square with sides of 150 pixels </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">e) A black vertical line that is 40 pixels long and a red square with sides of 100 pixel</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : b.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the statements below are true?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) A polyline is always filled. b) A polyline can not be filled.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) A polygon is always filled. d) A polygon is always closed</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">e) A polygon may be filled or not filled</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : b, d and e.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What code would you use to construct a 24-point bold serif font?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) new Font(Font.SERIF, 24,Font.BOLD); b) new Font(&#8220;SERIF&#8221;, 24, BOLD&#8221;); </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) new Font(&#8220;BOLD &#8220;, 24,Font.SERIF); d) new Font(&#8220;SERIF&#8221;, Font.BOLD,24); </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">e) new Font(Font.SERIF, &#8220;BOLD&#8221;, 24);</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : d.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What does the following paint( ) method draw?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Public void paint(Graphics g) {</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.drawString(&#8220;question #6&#8243;,10,0);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">}</span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) The string &#8220;question # 6&#8243;, with its top-left corner at 10,0 </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">b) A little squiggle coming down from the top of the component, a little way in from the left edge</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : b.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What does the following paint( ) method draw?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Public void paint(Graphics g) {</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.drawString(&#8220;question #6&#8243;,10,0);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">}</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) A circle at (100, 100) with radius of 44 b) A circle at (100, 44) with radius of 100 </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) A circle at (100, 44) with radius of 44 d) The code does not compile</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : d.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What is relationship between the Canvas class and the Graphics class?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : A Canvas object provides access to a Graphics object via its paint( ) method.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What are the Component subclasses that support painting. </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : The Canvas, Frame, Panel and Applet classes support painting.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What is the difference between the paint( ) and repaint( ) method? </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : The paint( ) method supports painting via a Graphics object. The repaint( ) method is used </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">to cause paint( ) to be invoked by the AWT painting method. </span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What is the difference between the Font and FontMetrics classes? </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : The FontMetrics class is used to define implementation-specific properties, such as ascent </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">and descent, of a Font object.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the following are passed as an argument to the paint( ) method?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) A Canvas object b) A Graphics object </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) An Image object d) A paint object</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : b.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the following methods are invoked by the AWT to support paint and repaint operations?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) paint( ) b) repaint( ) </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) draw( ) d) redraw( )</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the following classes have a paint( ) method?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) Canvas b) Image </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) Frame d) Graphics </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a and c.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the following are methods of the Graphics class?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) drawRect( ) b) drawImage( ) </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) drawPoint( ) d) drawString( )</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a, b and d.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which Font attributes are available through the FontMetrics class?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) ascent b) leading </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) case d) height</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a, b and d.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which of the following are true?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">The AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized. </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">The AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered. </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">The AWT automatically causes a window to be repainted when application data is changed. </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">The AWT does not support repainting operations. </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a and b.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Which method is used to size a graphics object to fit the current size of the window? </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : getSize( ) method.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What are the methods to be used to set foreground and background colors?</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : setForeground( ) and setBackground( ) methods.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) You have created a simple Frame and overridden the paint method as follows </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">public void paint(Graphics g) {</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.drawString(&#8220;Dolly&#8221;,50,10); }</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) What will be the result when you attempt to compile and run the program? </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) The string &#8220;Dolly&#8221; will be displayed at the centre of the frame</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">b) An error at compilation complaining at the signature of the paint method<br />
c) The lower part of the word Dolly will be seen at the top of the form, with the top hidden.<br />
d) The string &#8220;Dolly&#8221; will be shown at the bottom of the form </span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : c.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Where g is a graphics instance what will the following code draw on the screen. </span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">g.fillArc(45,90,50,50,90,180);</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting<br />
at an angle of 90 degrees traversing through 180 degrees counter clockwise.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">b) An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting<br />
at an angle of 90 degrees traversing through 180 degrees clockwise.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">c) An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45,<br />
90, starting at 90 degrees and traversing through 180 degrees counter clockwise.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">d) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a<br />
box of height 50, width 50 with a centre point of 90, 180.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : c.</span></p>
<p class="MsoNormal" style="line-height: 150%;"><strong><span style="font-size: 10pt; line-height: 150%; font-family: Arial; color: black;">Q) Given the following code<br />
import java.awt.*;<br />
public class SetF extends Frame{<br />
public static void main(String argv[]){<br />
SetF s = new SetF();<br />
s.setSize(300,200);<br />
s.setVisible(true);<br />
}<br />
}<br />
How could you set the frame surface color to pink</span><span style="color: black;"></span></strong></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">a) s.setBackground(Color.pink); b) s.setColor(PINK);<br />
c) s.Background(pink); d) s.color=Color.pink</span></p>
<p class="MsoNormal" style="line-height: 150%;"><span style="font-size: 10pt; line-height: 150%; font-family: Arial;">Ans : a.</span></p>
<p class="MsoNormal">
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-tracking/" title="Define Session Tracking">Define Session Tracking</a> (0)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-basics-interview-questions/" title="Java Basics Interview Questions">Java Basics Interview Questions</a> (1)</li><li>August 9, 2008 -- <a href="http://www.bestjavainterviewquestions.com/some-important-methos-in-applets/" title="Some important methos in Applets">Some important methos in Applets</a> (0)</li><li>February 9, 2009 -- <a href="http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/" title="Uploading Excel File  Using Jsp">Uploading Excel File  Using Jsp</a> (0)</li><li>July 21, 2010 -- <a href="http://www.bestjavainterviewquestions.com/using-serialization/" title="Using Serialization ">Using Serialization </a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/awt-interview-questions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWT Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/awt-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/awt-interview-questions/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 00:48:21 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[AWT Question]]></category>
		<category><![CDATA[awt questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=16</guid>
		<description><![CDATA[1. What is meant by Controls and what are different types of controls? à Controls are componenets that allow a user to interact with your application. The AWT supports the following types of controls: * Labels * Push buttons * Check boxes * Choice lists * Lists * Scroll bars * Text components These controls [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span> </span><strong>1. What is meant by Controls and what are different types of controls? </strong></p>
<p class="MsoNormal"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> Controls are componenets that allow a user to interact with your application.</p>
<p class="MsoNormal"><span> </span>The AWT supports the following types of controls:</p>
<p class="MsoNormal"><span> </span>* Labels</p>
<p class="MsoNormal"><span> </span>* Push buttons</p>
<p class="MsoNormal"><span> </span>* Check boxes</p>
<p class="MsoNormal"><span> </span>* Choice lists</p>
<p class="MsoNormal"><span> </span>* Lists</p>
<p class="MsoNormal"><span> </span>* Scroll bars</p>
<p class="MsoNormal"><span> </span>* Text components</p>
<p class="MsoNormal"><span> </span>These controls are subclasses of Component.</p>
<p class="MsoNormal"><strong><span> </span>2. <span> </span>Which method of the component class is used to set the position and the size of a component? </strong></p>
<p class="MsoNormal"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> setBounds().</p>
<p class="MsoNormal"><span> </span>The following code snippet explains this:</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>txtName.setBounds(x,y,width,height);</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>places upper left corner of the text field txtName at point (x,y) with the width and<span> </span><span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>height of the text field set as width and height.</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span>3. Which TextComponent method is used to set a TextComponent to the read-only state? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> setEditable()</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>4. How can the Checkbox class be used to create a radio button? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> By associating Checkbox objects with a CheckboxGroup.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>5. What methods are used to get and set the text label displayed by a Button object? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> getLabel( ) and setLabel( )</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>6. What is the difference between a Choice and a List? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> <em>Choice</em>: A Choice is displayed in a compact form that requires you to pull it down<span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>to see the list of available choices. Only one item may be selected from a Choice.<span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><em>List</em>: A List may be displayed in such a way that several List items are visible. A<span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>List supports the selection of one or more List items.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>7. What is the difference between a Scollbar and a Scrollpane? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> A Scrollbar is a Component, but not a Container. A Scrollpane is a Container and<span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>handles its own events and performs its own scrolling.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>8. Which are true about the Container class?</strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> * The validate( ) method is used to cause a Container to be laid out and</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>redisplayed.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* The add( ) method is used to add a Component to a Container.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* The getBorder( ) method returns information about a Container’s insets.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* getComponent( ) method is used to access a Component that is contained in a<span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Container.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Answers: a, b and d</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>9. Suppose a Panel is added to a Frame and a Button is added to the Panel.If the Frame’s font is set to 12-point TimesRoman, the Panel’s font is set to 10-point TimesRoman, and the Button’s font is not set, what font will be used to display the Button’s label?</strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>* 12-point TimesRoman</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* 11-point TimesRoman</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* 10-point TimesRoman</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* 9-point TimesRoman</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Answer: c.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>10. What are the subclasses of the Container class? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> The Container class has three major subclasses. They are:</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* Window</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* Panel</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* ScrollPane</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>11. Which object is needed to group Checkboxes to make them exclusive?</strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><span style="font-family: Wingdings;"><span>à</span></span>CheckboxGroup.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>12. What are the types of Checkboxes and what is the difference between them? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>Java supports two types of Checkboxes:</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* Exclusive</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* Non-exclusive.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>In case of exclusive Checkboxes, only one among a group of items can be selected <span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>at a time. I f an item from the group is selected, the checkbox currently checked is</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>deselected and the new selection is highlighted. The exclusive Checkboxes are also</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>called as Radio buttons. The non-exclusive checkboxes are not grouped together</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>and each one can be selected independent of the other.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><strong>13. What is a Layout Manager? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>A layout Manager is an object that is used to organize components in a container.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>14. what are the different Layout Managers available in java.awt and what is the default Layout manager for the panel and the panel<span> </span>subclasses? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> The different layouts available in java.awt are:</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>to right fashion.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>* BorderLayout: The elements of a BorderLayout are organized at the borders <span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>(North, South, East and West) and the center of a container.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* CardLayout: The elements of a CardLayout are stacked, one on top of the other,</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>like a deck of cards.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* GridLayout: The elements of a GridLayout are of equal size and are laid out</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>using the square of a grid.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>* GridBagLayout: The elements of a GridBagLayout are organized according to a <span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>grid.However, the elements are of different sizes and may occupy more</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><span> </span>than one row or column of the grid. In addition, the rows and columns may have <span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>different sizes.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>The default Layout Manager of Panel and Panel sub classes is FlowLayout.</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span>15. Can I add the same component to more than one container? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>No. Adding a component to a container automatically removes it from any previous</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>parent (container).</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span>16. How can we create a borderless window? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>Create an instance of the Window class, give it a size, and show it on the screen.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Frame aFrame = new Frame();</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Window aWindow = new Window(aFrame);</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>aWindow.setLayout(new FlowLayout());</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>aWindow.add(new Button(&#8220;Press Me&#8221;));</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>aWindow.getBounds(50,50,200,200);</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>aWindow.show();</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span>17. Can I create a non-resizable windows? If so, how? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><span> </span><span style="font-family: Wingdings;"><span>à</span></span>Yes. By using setResizable() method in class Frame.</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><strong>18. Which containers use a BorderLayout as their default layout? Which containers use a FlowLayout as their default layout? </strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><span style="font-family: Wingdings;"><span>à</span></span>The Window, Frame and Dialog classes use a BorderLayout as their default layout. <span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>The Panel and the Applet classes use the FlowLayout as their default layout.</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span><span> </span>19. How do you change the current layout manager for a container?</strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span>a. Use the setLayout method</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>b.Once created you cannot change the current layout manager of a component</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span>c.Use the setLayoutManager method</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span> </span><span> </span>d.Use the updateLayout method</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>Answer: a.</p>
<p class="MsoNormal" style="text-align: justify;"><strong><span> </span>20. What is the difference between a MenuItem and a CheckboxMenuItem?</strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span><span style="font-family: Wingdings;"><span>à</span></span> The CheckboxMenuItem class extends the MenuItem class to support a menu item</p>
<p class="MsoNormal" style="text-align: justify;"><span> </span>that may be checked or unchecked.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/deployment-descriptor/" title="Deployment Descriptor">Deployment Descriptor</a> (0)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>July 15, 2008 -- <a href="http://www.bestjavainterviewquestions.com/springs-interview-questions/" title="Springs Interview Questions">Springs Interview Questions</a> (0)</li><li>July 7, 2008 -- <a href="http://www.bestjavainterviewquestions.com/jms-interview-questions/" title="JMS INTERVIEW QUESTIONS">JMS INTERVIEW QUESTIONS</a> (1)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/write-a-note-on-ejb-frame-work/" title="Write a note on EJB frame work">Write a note on EJB frame work</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/awt-interview-questions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

