Friday, March 16, 2012

Swing Questions

____________________________________________________________________________________________________________________________________________________________

Heavyweight componants are not handled properly when they are placed inside the JScrollpane�s viewport because(Select Multiple)
A) JScrollPane is a lightweight component.
B) Viewport of JScrollPane which clips its scrollable child, is lightweight
C) None of the above
D) Either of the above.

Both the JScrollPane class and its viewport -- which clips its scrollable child -- are lightweight components. Consequently, heavyweight components cannot be handled properly when they are placed inside a JScrollPane's viewport. This is a window created by a little program that places both a Swing JButton and an AWT Button within a JScrollPane:

http://java.sun.com/products/jfc/tsc/articles/mixing/


____________________________________________________________________________________________________________________________________________________________
What are the restrictions imposed by the security manager on applets. (Select Multiple)
A) Cannot start any program on the host that is executing it.
B) Cannot read some system properties.
C) Cannot load libraries or define native methods.
D) Cannot read or write files on the host that is executing it.

The answer is all the above coz applets loaded over the net are prevented from reading and writing files on the client file system and from making network connections except to the originating host.In addition applets loaded over the net are prevented from starting other programs on the client. Applets loaded over the net are also not allowed to load libraries or to define native method calls.If an applet could define native method calls,that would give the applet direct access to the underlying computer.

so all the above mentioned options are correct

____________________________________________________________________________________________________________________________________________________________
All swing components are light weight componants except for (Select Multiple)
A) JWindow, JFrame
B) JDialog
C) JApplet
D) JPanel
Latest Answer : All components in Project Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components. Lightweight components, unlike their Abstract Window Toolkit (AWT) counterparts, do not depend on the local windowing toolkit.
ANS is: --->d ...

____________________________________________________________________________________________________________________________________________________________
_Lightweight components differ from heavy weight componants not because of one of the following reasons
A) A heavyweight component have transparent pixels which lightweight have opaque.
B) A lightweight can appear to be non-rectangular while heavyweight are always rectangular.
C) Mouse events on light weight componants fall through its parents while in the heavyweight it doesn�t.
D) On overlapping of the lightweight component over the heavy weight component the heavy weight component is always on top.
Explanation: lightweight component have transparent pixels which heavyweight have opaque.
___________________________________________________________________________________________________________________________________________________________
_The three most common z-order related problems have to do with Swings following componants. (Select Multiple)
A) JScrollPane.
B) JInternalFrame
C) JInternalFrame popup componants.
D) JPanel.
The three most common z-order-related problems have to do with Swing's JScrollPane and JInternalFrame classes, and its popup components. So the answer is "A,B,C".

___________________________________________________________________________________________________________________________________________________________
_The types of popups in swing are 1. Lightweight Popup2. Heavyweight popup3. Medium weight popup
A) 1, 2
B) 2, 3
C) 1, 3
D) 1, 2, 3
Swing attempts to maximize popup performance by dynamically choosing the most efficient container to display a popup just prior to showing the popup. The types of popups created are:

* LightWeight Popup: a lightweight container.
* MediumWeight Popup: an AWT heavyweight Panel.
* HeavyWeight Popup: a JWindow (heavyweight top-level window).

so the answer is "D" .
______________________________________________________________________________________________________________________________________________________
Fill in the blank :- the default look and feel of a swing component is

The package that contains Java Look and Feel is named javax.swing.plaf.metal, it is commonly referred to as Metal. Metal has been Sun's visual appearance of choice for Java programs. With J2SE 1.5, we will get a slightly new look, called Ocean, that will replace the old one (now to be called Steel).
Technically, Ocean is not a new L&F but implemented as javax.swing.plaf.metal.MetalTheme, and therefore aims to be compatible with existing Metal applications (concerning getPreferredSize(), for example). The Java look and feel is often referred to as a cross-platform look and feel, because it should be available on any environment providing Java and JFC.

_________________________________________________________________________________________________________________________________________________________________________
What are the borders provided by swings (Select Multiple)
A) Simple
B) Matte
C) Titled
D) Aggregate
Explanation: the fourth one is Compound

Swings provide all the above mentioned borders.Therefore the answer is all the above or u need to check all the optoins.
____________________________________________________________________________________________________________________________________________________________
What are invisible componants in swings ? (Select Multiple)
A) Componants which take space in the GUI on the client interface.
B) Componants which cannot perform painting operation.
C) Componants which can perform painting operation.
D) The componants that are visible but no componants can be added in it.

Ans B ____________________________________________________________________________________________________________________________________________________________
Which containers use border layout as their default layout ? (Select Multiple)
A) Panel
B) Dialog
C) Frame
D) Window
The default layout of a Panel is FlowLayout.
The default layout of Window class is BorderLayout.
BorderLayout is the default layout of the subclasses of window class such as Frame and Dialog.
So the answer would be B,C,D.

____________________________________________________________________________________________________________________________________________________________
The command �codebase� is used in applets when
A) When the applet class file is not in the same directory
B) When the applet class file is in the same directory
C) When we need to get the parameters of the applet
D) None of the above

By default, a browser looks for an applet's class and archive files in the same directory as the HTML file that has the <APPLET> tag. (If the applet's class is in a package, then the browser uses the package name to construct a directory path underneath the HTML file's directory.) Sometimes, however, it's useful to put the applet's files somewhere else. You can use the CODEBASE attribute to tell the browser in which directory the applet's files are located:

<APPLET CODE=AppletSubclass.class CODEBASE=aURL
WIDTH=anInt HEIGHT=anInt>
</APPLET>


____________________________________________________________________________________________________________________________________________________________
The layout of a container can be altered by using which of the following methods :-
A) setLayout(aLayoutManager)
B) layout(aLayoutManager)
C) addLayout(aLayoutManager)
D) setLayoutManager(aLayoutManager)

The layout of contaniner can be changed by
a. setLayout(LayoutManager)
eg: pan.setLayout(new BorderLayout())____________________________________________________________________________________________________________________________________________________________
Using a FlowLayout Manager, which of the following is the correct way to add elements to a container. (Select Multiple)
A) add(component);
B) set(component);
C) add(x,y, component);
D) add(�Center�,component);
Using FlowLayout manager adding components to a container can be done using add(component).So the answer is "A".

____________________________________________________________________________________________________________________________________________________________
What is the difference between scrollbar and scrollpane(Select Multiple)
A) Scrollbar is a component while scrollpane is a container
B) Scrollbar handles its own events while scrollpane does not
C) Scrollpane handles its own events and performs its own scrolling.
D) All of the above.

The scrollbar is a component while scrollpane is a container.Scrollpane handles its own events and performs its own scrolling.So answer is "A,C".

____________________________________________________________________________________________________________________________________________________________
State true or false :-Images can be displayed in swings
A) True
B) False
TRUE

____________________________________________________________________________________________________________________________________________________________
What are the features coming with JFC?. (Select Multiple)
A) Pluggable Look-and-Feel
B) Accessibility API
C) Java 2D/API(JDK 1.2).
D) Drag and Drop Support(JDK 1.2)
The JFC -java Foundation classes have five major parts :
AWT,SWING,ACCESSIBILITY,JAVA 2D,DRAG & DROP as well.
PLAF is included with swing.
so answers are all of the above.
____________________________________________________________________________________________________________________________________________________________
Fill in the blanks :- The meaning of �x� in javax.swing is _______________
A) Extension of java

____________________________________________________________________________________________________________________________________________________________
State true or false :- The event delegation model, introduced in release 1.1 of the JDK, is fully compatible with the event model.
A) True
B) False
Answer is false.

As earlier event model with jdk1.0 only components classes have event handling methods and so no other object can handle events.
But with jdk1.1 delegation event model component event handling is replaced event listener interfaces and adapter classes.Any class can use these listeners and classes.it is not backward compatible.
____________________________________________________________________________________________________________________________________________________________
State true or false :- A component subclass that has executed enableEvents( ) to enable processing of a certain kind of event cannot also use an adapter as a listener for the same kind of event.
A) True
B) False

The answer is false,
Processing of a certain kind of event can use an adapter as a listener for the same kind of event.

____________________________________________________________________________________________________________________________________________________________
Fill in the blanks :- The highest-level event class of the event-delegation model is _____
A) java.util.eventObject
____________________________________________________________________________________________________________________________________________________________
What class is the top of the AWT event hierarchy?
A) java.awt.AWTEvent
B) java.awt.Event
C) java.util.eventObject
D) javax.swing.Object
Explanation: The java.awt.AWTEvent class is the highest-level class in the AWT event class hierarchy.
Event types are encapsulated in a class hierarchy rooted at java.util.EventObject. An event is propagated from a "Source" object to a "Listener" object by invoking a method on the listener and passing in the instance of the event subclass which defines the event type generated.

____________________________________________________________________________________________________________________________________________________________
What class is the top of the AWT event hierarchy?
A) java.awt.AWTEvent
B) java.awt.Event
C) java.util.eventObject
D) javax.swing.Object
Explanation: The java.awt.AWTEvent class is the highest-level class in the AWT event class hierarchy.
The class which is at the top of the AWT event hierarchy is java.util.eventObject ie " c".

This is kind of a dicy question:
But in Java the event heirarchy goes like :
java.lang.object -> java.util.EventObject -> java.awt.AWTEvent.
So the java.util.EventObject is the superclass of all events.
But java.awt.AWTEvent is the superclass of all AWT events like low level (Componet ,Key,Focus,Mouse) and semantic events(Action,Text,Item,Adjustment).

____________________________________________________________________________________________________________________________________________________________
Which of the following methods are invoked by the AWT to support paint and repaint operations?
A) paint( )
B) repaint( )
C) draw( )
D) redraw( )
Ans A
____________________________________________________________________________________________________________________________________________________________
Which of the following are passed as an argument to the paint( ) method?
A) A Canvas object
B) A Graphics object
C) An Image object
D) A paint object
The Graphic object is passed as argument to paint() method.This method is invoked by Swing to draw componet.
public abstract class Graphics
extends Object
Ans B
____________________________________________________________________________________________________________________________________________________________
Which of the following classes have a paint( ) method? (Select Multiple)
A) Canvas
B) Image
C) Frame
D) Graphics
Canvas and Frame
____________________________________________________________________________________________________________________________________________________________
Which of the following are methods of the Graphics class? (Select Multiple)
A) drawRect( )
B) drawImage( )
C) drawPoint( )
D) drawString( )

A,D,B

____________________________________________________________________________________________________________________________________________________________
Which of the following options are correct regarding the organization of layouts (Select Multiple)
A) FlowLayout : The elements of a FlowLayout are organized in a top to bottom, left to right fashion.
B) BorderLayout : The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.
C) CardLayout : The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.
D) GridBagLayout : The elements of a GridLayout are of equal size and are laid out using the square of a grid
Explanation: The d option is wrong it describes the GridLayout.


____________________________________________________________________________________________________________________________________________________________
Which layout should you use to organize the components of a container in a tabular form?
A) CardLayout
B) BorederLayout
C) FlowLayout
D) GridLayout
Ans D
____________________________________________________________________________________________________________________________________________________________
An application has a frame that uses a Border layout manager. Why is it probably not a good idea to put a vertical scroll bar at North in the frame?
A) The scroll bar�s height would be its preferred height, which is not likely to be enough.
B) The scroll bar�s width would be the entire width of the frame, which would be much wider than necessary.
C) Both a and b.
D) Neither a nor b. There is no problem with the layout as described.

The vertical scroll bar is wide and fat and it is not very useful.

Option B is correct.
____________________________________________________________________________________________________________________________________________________________
If a frame uses a Grid layout manager and does not contain any panels, then all the components within the frame are the same width and height.
A) True
B) False
As the Grid Layout distributes the space into equal cells of a grid, and each of the 'cells' will allow th componenet to take the entire space.

____________________________________________________________________________________________________________________________________________________________
How do you indicate where a component will be positioned using Flowlayout?
A) North, South, East, West
B) Assign a row/column grid reference
C) Pass a X/Y percentage parameter to the add method
D) Do nothing, the FlowLayout will position the component

Ans D ____________________________________________________________________________________________________________________________________________________________
Which of the following statement(s) are true?
A) The default layout manager for an Applet is FlowLayout
B) The default layout manager for an application is FlowLayout
C) A layout manager must be assigned to an Applet before the setSize method is called
D) The FlowLayout manager attempts to honor the preferred size of any components
Ans A)
____________________________________________________________________________________________________________________________________________________________
Which of the following may contain a menu bar?
A) A panel
B) A frame
C) An applet
D) A menu bar
Frame
____________________________________________________________________________________________________________________________________________________________
Which of the following (is)are true?
A) A Dialog can have a MenuBar.
B) MenuItem extends Menu.
C) A MenuItem can be added to a Menu.
D) A Menu can be added to a Menu.
Ans C
____________________________________________________________________________________________________________________________________________________________
Which TextComponent method is used to set a TextComponent to the read-only state ?
A) setReadOnly()
B) setEditOnly()
C) setEditable()
D) setTextReadOnly()
setEditable(false)____________________________________________________________________________________________________________________________________________________________
Which of the following methods are defined on the Graphics class:
A) drawLine(int, int, int, int)
B) drawImage(Image, int, int, ImageObserver)
C) drawString(String, int, int)
D) add(Component);
E) setVisible(boolean);
F) setLayout(Object);
The correct answer is a,b,c :

a) drawLine(int x1, int y1, int x2, int y2)

b) drawImage(Image img, int x, int y, ImageObserver observer)

c) drawString(String str, int x, int y)

____________________________________________________________________________________________________________________________________________________________
Which of the following layout managers honours the preferred size of a component:
A) CardLayout
B) FlowLayout
C) BorderLayout
D) GridLayout

Many layout managers do not pay attention to a component's requested maximum size. However, BoxLayout and SpringLayout do. Furthermore, GroupLayout provides the ability to set the minimum, preferred or maximum size explicitly, without touching the component.
Flow layout ?????
____________________________________________________________________________________________________________________________________________________________
Which of the following components allow multiple selections? (Select Multiple)
A) Non-exclusive Checkboxes.
B) Radio buttons.
C) Choice.
D) List.
A & D ????
____________________________________________________________________________________________________________________________________________________________
What is the result of executing the following Java class: import java.awt.*; public class FrameTest extends Frame {public FrameTest() {add (new Button("First"));add (new Button("Second"));add (new Button("Third"));pack();setVisible(true);}public static void main(String args []) {new FrameTest();}} Select from the following options:
A) Only the "third" button is displayed.
B) A runtime exception is generated (no layout manager specified).
C) Only the "first" button is displayed.
D) Only the "second" button is displayed.

ans A
____________________________________________________________________________________________________________________________________________________________
Which of the following are true?
A) The event-inheritance model has replaced the event-delegation model.
B) The event-inheritance model is more efficient than the event-delegation model.
C) The event-delegation model uses event listeners to define the methods of event-handling classes.
D) The event-delegation model uses the handleEvent( ) method to support event handling.
Ans C
____________________________________________________________________________________________________________________________________________________________
When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?
A) The first object that was added as listener.
B) The last object that was added as listener.
C) There is no way to determine which listener will be invoked first.
D) It is impossible to have more than one listener for a given event.

??????????????????____________________________________________________________________________________________________________________________________________________________
Which of the following are true about MouseListenerInterfaces? (Select Multiple)
A) The MouseListener interface defines methods for handling mouse clicks.
B) The MouseMotionListener interface defines methods for handling mouse clicks.
C) The MouseClickListener interface defines methods for handling mouse clicks.
D) The MouseListenerInheritance interface defines methods for handling the clicking of a button.

The following options are correct:
A) TrueExplanation: MouseListener Interface defines the methods for mouse clicks, mouse pressed etc. Hence this is true.
B) TrueExplanation: The MouseMotionListener defines methods of MouseClicks as well as mouse movement, hovering, lost focus etc.
C) FalseExplanation: This is no listener named MouseClickListener in Swing
D) FalseExplanation: There is no interface as MouseListenerInheritence in Swing


____________________________________________________________________________________________________________________________________________________________
Which of the following are true? (Select Multiple)
A) A component may handle its own events by adding itself as an event listener.
B) A component may handle its own events by overriding its event-dispatching method.
C) A component may not handle oits own events.
D) A component may handle its own events only if it implements the handleEvent( ) method.

???????????
____________________________________________________________________________________________________________________________________________________________
Which of the following option(s) doesn�t correctly describe the Applet�s Life Cycle methods?
A) init( ) method - Can be called when an applet is first loaded.
B) start( ) method - Can be called each time an applet is started.
C) paint( ) method - Can be called when the applet is minimized or refreshed.
D) destroy( ) method - Can be called when the browser moves off the applet�s page.
Explanation: it is the explanation for stop(), while destroy( ) method - Can be called when the browser is finished with the applet.

Answer) c)paint() doesn't come under the lifecycle methods of Applet

____________________________________________________________________________________________________________________________________________________________
All Applets are subclasses of Applet.
A) True
B) False

TRUE
____________________________________________________________________________________________________________________________________________________________
All Applets must import java.applet and java.awt.
A) True
B) False

True ??
_____________________________________________________________________________________________________________________________________________________
Which classes and interfaces does Applet class consist? (Select Multiple)
A) The Applet class
B) AppletContext Interface.
C) AppletStub Interface
D) AudioClip Interface
All of the above
____________________________________________________________________________________________________________________________________________________________
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("Color.cyan");
D) g.setColor("cyan�);
E) g.setColor(new Color(cyan));

Ans A)
____________________________________________________________________________________________________________________________________________________________
What does the following code draw?g.setColor(Color.black);g.drawLine(10, 10, 10, 50);g.setColor(Color.RED);g.drawRect(100, 100, 150, 150);
A) A red vertical line that is 40 pixels long and a red square with sides of 150 pixels
B) A black vertical line that is 40 pixels long and a red square with sides of 150 pixels
C) A black vertical line that is 50 pixels long and a red square with sides of 150 pixels
D) A red vertical line that is 50 pixels long and a red square with sides of 150 pixels
E) A black vertical line that is 40 pixels long and a red square with sides of 100 pixel

aNS b
____________________________________________________________________________________________________________________________________________________________
Which Font attributes are available through the FontMetrics class? (Select Multiple)
A) ascent
B) leading
C) case
D) height
A,B,D
____________________________________________________________________________________________________________________________________________________________
Which of the following are true? (Select Multiple)
A) The AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.
B) The AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.
C) The AWT automatically causes a window to be repainted when application data is changed.
D) The AWT does not support repainting operations.
A and C
____________________________________________________________________________________________________________________________________________________________
You have created a simple Frame and overridden the paint method as follows public void paint(Graphics g){ g.drawString("Dolly",50,10);}What will be the result when you attempt to compile and run the program?
A) The string "Dolly" will be displayed at the centre of the frame
B) An error at compilation complaining at the signature of the paint method
C) The lower part of the word Dolly will be seen at the top of the form, with the top hidden.
D) The string "Dolly" will be shown at the bottom of the form
C ???
____________________________________________________________________________________________________________________________________________________________
A text field has a variable-width font. It is constructed by calling new TextField("iiiii"). What happens if you change the contents of the text field to "wwwww"? (Bear in mind that is one of the narrowest characters, and w is one of the widest.)
A) The text field becomes wider.
B) The text field becomes narrower.
C) The text field stays the same width; to see the entire contents you will have to scroll by using the � and à keys.
D) The text field stays the same width; to see the entire contents you will have to scroll by using the text field�s horizontal scroll bar.

Ans B ???
____________________________________________________________________________________________________________________________________________________________
What are the immediate super classes of the following classes? (Select Multiple)
A) Container - Component
B) MenuComponent - Object
C) Dialog - Window
D) Applet - Panel
A,B,C
____________________________________________________________________________________________________________________________________________________________
Which Component method is used to access a component's immediate Container?
A) getVisible()
B) getImmediate
C) getParent()
D) getContainer()
C
____________________________________________________________________________________________________________________________________________________________
Which of the following are direct or indirect subclasses of Component?
A) Button
B) Label
C) CheckboxMenuItem
D) Toolbar
E) Frame
All
____________________________________________________________________________________________________________________________________________________________
Which of the following are direct or indirect subclasses of Container? (Select Multiple)
A) Frame
B) TextArea
C) MenuBar
D) FileDialog
E) A,E are the sub classes of container
____________________________________________________________________________________________________________________________________________________________
Which method is used to set the text of a Label object?
A) setText( )
B) setLabel( )
C) setTextLabel( )
D) setLabelText( )
A
____________________________________________________________________________________________________________________________________________________________
Which method will cause a Frame to be displayed?
A) show( )
B) setVisible( )
C) display( )
D) displayFrame( )
A,B
____________________________________________________________________________________________________________________________________________________________
Why Some of Components like JDialog,JFrame are called as Heavy weight Components , event they are in javax.swing ?

____________________________________________________________________________________________________________________________________________________________
whatis difference between applet and swing ,is it possible connect database through appletbased gui?

Yes it is possibe.You can communicate to databases through applet using Applet-Servlet Communications.What u need is to use URL class to send Query to servlet which interacts with the database and send the Query results back to the applet.
____________________________________________________________________________________________________________________________________________________________
what is the differance between Frame and window?

Frame is a top level window with a titlebar and a menubar, Frame is the subclass of WindowFrame is a container for other java components,Window is a top level window with no titllebar and no menubar,
____________________________________________________________________________________________________________________________________________________________

No comments: