Java Swings Interview Questions



Q) In which package are most of the AWT events that support the event-delegation model defined?
A)
Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.

Q) Which class is the immediate superclass of the MenuComponent class?
A)
Object

Q) Which containers may have a MenuBar?
A) Frame

Q) What is the relationship between the Canvas class and the Graphics class?
A)
A Canvas object provides access to a Graphics object via its paint() method.

Q) How are the elements of a BorderLayout organized?
A)
The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.

Q) What is the difference between a Window and a Frame?
A)
The Frame class extends Window to define a main application window that can have a menu bar.

Q) What is the difference between the Font and FontMetrics classes?
A)
The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

Q) How are the elements of a CardLayout organized?
A)
The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.

Q) What is the relationship between clipping and repainting?
A)
When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.

Q) What is the relationship between an event-listener interface and an event-adapter class?
A)
An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

Q) How can a GUI component handle its own events?
A)
A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Q) How are the elements of a GridBagLayout organized?
A)
The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

Q) What advantage do Java’s layout managers provide over traditional windowing systems?
A)
Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.

Q) What is the difference between the paint() and repaint() methods?
A)
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Q) How can the Checkbox class be used to create a radio button?
A)
By associating Checkbox objects with a CheckboxGroup

Q) Difference between paint() and paintComponent()?
A)
The key point is that the paint() method invokes three methods in the following order:
a) paintComponent()

b) paintBorder()

c) paintChildren()
As a general rule, in Swing, you should be overriding the paintComponent method unless you know what you are doing.
gaintComponent() paints only component (panel) but paint() paints component and all its children.

Q) What is the difference between paint(), repaint() and update() methods within an applet which contains images?
A)
paint : is only called when the applet is displayed for the first time, or when part of the applet window has to be redisplayed after it was hidden.
repaint : is used to display the next image in a continuous loop by calling the update method.
update : you should be aware that, if you do not implement it yourself, there is a standard update method that does the following : it will reset the applet window to the current background color (i.e. it will erase the current image)  it will call paint to construct the new image

Q) What is the name of the design pattern that Java uses for all Swing components?
A)
MVC(Model View Controller) pattern

Q) Name few LayoutManagers in Java.
A)

Flow Layout Manager
Grid   Layout Manager
Border Layout Manager
Box Layout Manager
Card Layout Manager
GridBag Layout Manager

Random Posts

  • Define Static Keyword
  • Java RMI Interview questions
  • Life Cycle of stateless session bean
  • Core Java Inteview Questions
  • Explain Jsp Directives

Post a Comment