You are on page 1of 4

Unit-I Swing Solution for Review Questions Q.1 a.

Features of JFC
JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. It is defined as containing the features shown in the table below. Description Includes everything from buttons to split panes to tables. Many components are Swing GUI capable of sorting, printing, and drag and drop, to name a few of the supported Components features. The look and feel of Swing applications is pluggable, allowing a choice of look and feel. For example, the same program can use either the Java or the Windows Pluggable Look-andlook and feel. Additionally, the Java platform supports the GTK+ look and feel, Feel Support which makes hundreds of existing look and feels available to Swing programs. Many more look-and-feel packages are available from various sources. Enables assistive technologies, such as screen readers and Braille displays, to get information from the user interface. (for people with disabilities Software developers are slowly becoming aware of the importance of "Assistive Technology" due to federal regulations and market realities. (Broadly speaking, Assistive Technology is any technology that enables Accessibility API people to do something they otherwise couldn't.) "The Java Accessibility API was designed to allow people with disabilities greater access to the world of Web technology -- both at home and in the workplace," said Jon Kannegaard, vice president of software products at Sun's JavaSoft division. "For example, a developer can now create a single application to be used by users with and without disabilities at the same time.") Enables developers to easily incorporate high-quality 2D graphics, text, and Java 2D API images in applications and applets. Java 2D includes extensive APIs for generating and sending high-quality output to printing devices. Allows developers to build applications that can interact with users worldwide in their own languages and cultural conventions. With the input method framework Internationalization developers can build applications that accept text in languages that use thousands of different characters, such as Japanese, Chinese, or Korean. Feature

b. JMenu
Purpose: The JMenuBar controls the bar along the top of the program (The one that has File, Edit etc). The JMenuBar is placed on the MenuBar in the JFrame. The MenuBar sits above the ContentPane. Constructors:
1. JMenu()

Constructs a new JMenu with no text.


2. JMenu(String s)

Constructs a new JMenu with the supplied string as its text.

Parameters: s - the text for the menu label Methods: 1. add


public JMenuItem add(JMenuItem menuItem)

Appends a menu item to the end of this menu. Returns the menu item added. Parameters:
menuItem - the JMenuitem to be added

Returns: the JMenuItem added 2. add


public Component add(Component c)

Appends a component to the end of this menu. Returns the component added. Parameters:
c - the Component to add

Returns: the Component added 3. addSeparator


public void addSeparator()

Appends a new separator to the end of the menu.

Q.2 JCheckBox Purpose:


An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user. By convention, any number of check boxes in a group can be selected.

How to create object of JCheckBox:


Constructors:
JCheckBox(String text)

Creates an initially unselected check box with text.


JCheckBox(String text, boolean selected)

Creates a check box with text and specifies whether or not it is initially selected.
JCheckBox(String text, Icon icon)

Creates an initially unselected check box with the specified text and icon.
JCheckBox(String text, Icon icon, boolean selected)

Creates a check box with text and icon, and specifies whether or not it is initially selected. Code Snippet: JCheckBox c=new JCheckBox( Sports , new ImageIcon( sports.gif ),true)

Q.8 i)JFrame. setDefaultCloseOperation


public void setDefaultCloseOperation(int operation)

Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices:
y DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object. HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects. DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects. EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit

y y y

method. Use this only in applications.

The value is set to HIDE_ON_CLOSE by default. Changes to the value of this property cause the firing of a property change event, with property name "defaultCloseOperation".

Q.10
1. JList display all items at once. JComboBox display the selected item only (selected from a pull-down list) ; 2. Also in a JComboxBox, you can select only one value at a time whereas in JList, you can select multiple values unless you've disabled it through your code. They are two different controls. 3. A combo box can be configured so the user can type an entry into the top portion of the control. This allows the user to enter his choice without selecting from the list. By default, a combo box is not editable. It can be made so by passing true to the setEditable method. The isEditable method returns the current state of the editable property. Whereas JList doesnt allow the user to enter his choice at the execution time.

You might also like