Swing interview questions – Part 3
31. How are the elements of different layouts organized?
The elements of a FlowLayout are organized in a top to bottom, left to right fashion. The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. The elements of a CardLayout are stacked, on top of the other, like a deck of cards. The elements of a GridLayout are of equal size and are laid out using the square of a grid. The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes. It is the most flexible layout.
32. What are types of applets?
There are two different types of applets. Trusted Applets and Untrusted applets. Trusted Applets are applets with predefined security and Untrusted Applets are applets without any security.
33. What are the restrictions imposed by a Security Manager on Applets?
Applets cannot read or write files on the client machine that’s executing it. They cannot load libraries or access native libraries. They cannot make network connections except to the host that it came from. They cannot start any program on the client machine. They cannot read certain system properties. Windows that an applet brings up look different than windows that an application brings up.
34. What is the difference between the Font and FontMetrics classes?
The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
35. What is the relationship between an event-listener interface and an event-adapter class?
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.
36. How can a GUI component handle its own events?
A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.
37. What is the difference between the paint() and repaint() methods?
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.
38. What interface is extended by AWT event listeners?
All AWT event listeners extend the java.util.EventListener interface.
39. What is Canvas ?
Canvas is a Component subclass which is used for drawing and painting. Canvas is a rectangular area where the application can draw or trap input events.
40. What is default Look-and-Feel of a Swing Component?
41. What are the features of JFC?
Pluggable Look-and-Feel, Accessibility API, Java 2D API, Drag and Drop Support.
42. What does x mean in javax.swing?
Extension of java.
43. What are invisible components?
They are light weight components that perform no painting, but can take space in the GUI. This is mainly used for layout management.
44. What is the default layout for a ContentPane in JFC?
45. What does Realized mean?
Realized mean that the component has been painted on screen or that is ready to be painted. Realization can take place by invoking any of these methods. setVisible(true), show() or pack().