Java AWT Interview Questions
- 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 are subclasses of Component.
- Which method of the component class is used to set the position and the size of a component? - setBounds(). The following code snippet explains this:
txtName.setBounds(x,y,width,height);
places upper left corner of the text field txtName at point (x,y) with the width and height of the text field set as width and height.
- Which TextComponent method is used to set a TextComponent to the read-only state? - setEditable()
- How can the Checkbox class be used to create a radio button? - By associating Checkbox objects with a CheckboxGroup.
- What methods are used to get and set the text label displayed by a Button object? - getLabel( ) and setLabel( )
- What is the difference between a Choice and a List? - Choice: A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. List: A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
- What is the difference between a Scollbar and a Scrollpane? - A Scrollbar is a Component, but not a Container. A Scrollpane is a Container and handles its own events and performs its own scrolling.
- Which are true about the Container class?
- The validate( ) method is used to cause a Container to be laid out and redisplayed.
- The add( ) method is used to add a Component to a Container.
- The getBorder( ) method returns information about a Container’s insets.
- getComponent( ) method is used to access a Component that is contained in a Container.
Answers: a, b and d
- 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?
- 12-point TimesRoman
- 11-point TimesRoman
- 10-point TimesRoman
- 9-point TimesRoman
Answer: c.
- What are the subclasses of the Container class? - The Container class has three major subclasses. They are:
- Window
- Panel
- ScrollPane























