Documents

Swing

Description
notes of swing
Categories
Published
of 8
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  Swing 1.   Write a short note on the advantages/features of JFC. (Any 6: 1M each) [1]   Pluggable Look and Feel:  Instead of being restricted to a single look and feel , we can select a look and feel and plug it in . An interface made of Swing components can look like a Win32 app, a Motif app, or a Mac app. It can use the new Metal look and feel. Developers can use standard Swing components and design their own look and feel (L&F) for them, and even allow users to select the look and feel they prefer. The plaf package includes the standard Pluggable Look And Feel classes. [2]   MVC Architecture:  The Model-View-Controller (MVC) architecture is used consistently throughout the Swing component set. The View and Controller parts of the architecture are combined in the component. Each component has an associated Model class and an interface it uses. We can provide our own data-model for a component by subclassing the Model class or by implementing the appropriate interface. [3]   Keystroke Handling:  The JComponent architecture makes it easy to handle keyboard events in nested components. [4]   Action Objects: Action-interface objects provide a single point of control for  program actions. [5]   Virtual Desktops: The JDesktopPane and JInternalFrame classes can be used to create a virtual desktop, or multiple document interface . A JInternalFrame can be specified as iconizable, expandable, or closable, while the JDesktopPane provides real estate for them to operate in. [6]   Compound Borders: Insets (the space between the edges of the component and the area it is drawn in) can be specified with a blank border. In addition, many  border styles are available, which can be combined to create compound borders. [7]   Customized Dialogs: The JOptionPane class provides a variety of static methods that you can invoke to create and display both message dialogs and user-choice dialogs in a variety of formats. [8]   Standard Dialog Classes: Standard dialogs currently available include: JFileChooser  and JColorChooser  [9]   Structured Table and Tree Components: The JTable class provides a data-aware matrix. JTree provides hierarchical-structuring of data elements. [10]   Powerful Text Manipulations: In addition to single-font text fields and text areas, Swing provides a JPassword field for hidden input and a JTextPane class for displaying multi-font text. In addition, the JEditorPane class provides editing capabilities for multi-font text, while the text.html and text.rtf packages handle text encoded in HyperText Markup Language (HTML) or Rich Text Format (RTF). [11]   Generic Undo Capabilities: The undo package provides generic undo capabilities that can be used in a variety of situations. [12]   Accessibility Support: Swing has built-in support for developers to make  products that are compatible with Assistive Technologies (for alternative interfaces like, for example, braille.) All of the Swing components implement interface Accessible.    2.   How are swing components different from AWT components? (1M each) The AWT components are those provided by the JDK 1.0 and 1.1 platforms. The Java 2 Platform still supports the AWT components. We can identify Swing components because their names start with J. The AWT button class, for example, is named Button, while the Swing button class is named JButton. The AWT components are in the java.awt package, while the Swing components are in the javax.swing package. The biggest difference between the AWT components and Swing components is that the Swing components are implemented with absolutely no native code. Since Swing components aren't restricted to the least common denominator -- the features that are present on every platform -- they can have more functionality than AWT components. Even the simplest Swing components have capabilities far beyond what the AWT components offer:    Swing buttons and labels can display images instead of, or in addition to, text.    We can easily add or change the borders drawn around most Swing components. For example, it's easy to put a box around the outside of a container or label.    We can easily change the behavior or appearance of a Swing component by either invoking methods on it or creating a subclass of it.    Swing components don't have to be rectangular. Buttons, for example, can  be round.    Assistive technologies such as screen readers can easily get information from Swing components. For example, a tool can easily get the text that's displayed on a button or label. Swing lets you specify which look and feel your program's GUI uses. By contrast, AWT components always have the look and feel of the native platform. 3.   Write short note on JFrame: (Description 2M + Constructor 2M + Methods 2M)    (Purpose) JFrame  class is an extended version of  java.awt.Frame  that adds support for the JFC/Swing component architecture.    A JFrame  object is a window with borders and a title bar. It can have a menu bar also.    A JFrame  has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the JFrame  when the user closes the window. To change the default behavior, we invoke the method setDefaultCloseOperation(int operation). Operations must    be one of the following values.     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 method. Use this only in applications. The value is set to HIDE_ON_CLOSE by default. Constructors 1)   JFrame(): 2)   JFrame(String title): If we pass a String  object to the constructor, the content of the string appears in the title bar of the frame window. Methods 1)   Container getContentPane(): Returns the contentPane object for this frame. 2)   void setContentPane(Container contentpane): Sets the contentPane property. 3)   JMenuBar getJMenuBar(): Returns the menubar set on this frame. 4)   void setJMenuBar(JMenuBar menubar): sets the menubar for this frame 5)   void setDefaultCloseOperation(int operation): Sets the operation that will happen by default when the user initiates a “close” on this frame 6)   void setVisible(boolean b): Shows or hides this component depending on the value of parameter b. 7)   Graphics getGraphics(): Creates a graphics context for this component. This method will return null if this component is currently not displayable. Code Snippet JFrame jf = new JFrame(“Demo”);  jf.setLayout(new FlowLayout());  jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(300,300); jf.setVisible(true); 4.   Write a short note on Text-Entry Components    Swing text components display text and optionally allow the user to edit the text. Programs need text components for tasks ranging from the straightforward (enter a word and press Enter) to the complex (display and edit styled text with embedded images in an Asian language). Swing provides six text components, along with supporting classes and interfaces that meet even the most complex text requirements. In spite of their different uses and capabilities, all Swing text components inherit from the same superclass, JTextComponent, which provides a highly-configurable and powerful foundation for text manipulation. The following figure shows the JTextComponent hierarchy. Group Description Swing Classes Text Controls Also known simply as text fields, text controls can display only one line of editable text. Like buttons, they generate action events. Use them to get a small amount of textual information from the user and perform an action after the text entry is complete. JTextField and its subclasses JPasswordField And JFormattedTextField  Plain Text Areas JTextArea can display multiple lines of editable text. Although a text area can display text in any font, all of the text is in the same font. Use a text area to allow the user to enter unformatted text of any length or to display unformatted help information. JTextArea 
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks