Wednesday, 11 February 2009

Java™ How to Program, Sixth Edition - Part11

Few weeks back i started reading Java™ How to Program, Sixth Edition By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

Nice book written By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

I wanted to share few quotations found the book from the 11th chapter.

1) A graphical user interface (GUI) presents a user-friendly mechanism for interacting with an application. A GUI gives an application a distinctive "look" and "feel."

2) Providing different applications with consistent, intuitive user interface components allows users to be somewhat familiar with an application, so that they can learn it more quickly.

3) GUIs are built from GUI componentssometimes called controls or widgets.

4) Most applications use windows or dialog boxes (also called dialogs) to interact with the user.

5) Class JOptionPane (package javax.swing) provides prepackaged dialog boxes for both input and output. JOptionPane static method showInputDialog displays an input dialog.

6) A prompt typically uses sentence-style capitalizationa style that capitalizes only the first letter of the first word in the text unless the word is a proper noun.

7) An input dialog can input only input Strings. This is typical of most GUI components.

8) JOptionPane static method showMessageDialog displays a message dialog.

9) Most Swing GUI components are located in package javax.swing. They are part of the Java Foundation Classes (JFC)Java's libraries for cross-platform GUI development.

10) Together, the appearance and the way in which the user interacts with the application are known as that application's look-and-feel. Swing GUI components allow you to specify a uniform look-and-feel for your application across all platforms or to use each platform's custom look-and-feel.

11) Lightweight Swing components are not tied to actual GUI components supported by the underlying platform on which an application executes.

12) Several Swing components are heavyweight components that require direct interaction with the local windowing system, which may restrict their appearance and functionality.

13) Class Component (package java.awt) declares many of the attributes and behaviors common to the GUI components in packages java.awt and javax.swing.

14) Class Container (package java.awt) is a subclass of Component. Components are attached to Containers so the Components can be organized and displayed on the screen.

15) Class JComponent (package javax.swing) is a subclass of Container. JComponent is the superclass of all lightweight Swing components and declares their common attributes and behaviors.

16) Some common JComponent features include a pluggable look-and-feel, shortcut keys called mnemonics, tool tips, support for assistive technologies and support for user interface localization.

17) Most windows are instances of class JFrame or a subclass of JFrame. JFrame provides the basic attributes and behaviors of a window.

18) A JLabel displays a single line of read-only text, an image, or both text and an image. Text in a JLabel normally uses sentence-style capitalization.

19) When building a GUI, each GUI component must be attached to a container, such as a window created with a JFrame.

20) Many IDEs provide GUI design tools in which you can specify the exact size and location of a component by using the mouse, then the IDE will generate the GUI code for you.

21) JComponent method setToolTipText specifies the tool tip that is displayed when the user positions the mouse cursor over a lightweight component.

22) Container method add attaches a GUI component to a Container.

23) Class ImageIcon (package javax.swing) supports several image formats, including Graphics Interchange Format (GIF), Portable Network Graphics (PNG) and Joint Photographic Experts Group (JPEG).

24) Method getClass (of class Object) retrieves a reference to the Class object that represents the the class declaration for the object on which the method is called.

25) Class method getresource returns the location of its argument as a URL. Method getresource uses the Class object's class loader to determine the location of the resource.

26) Interface SwingConstants (package javax.swing) declares a set of common integer constants that are used with many Swing components.

27) The horizontal and vertical alignments of a JLabel can be set with methods setHorizontalAlignment and setVerticalAlignment, respectively.

28) JLabel method setText sets the text displayed on a label. The corresponding method getText retrieves the current text displayed on a label.

29) JLabel method setIcon specifies the Icon to display on a label. The corresponding method getIcon retrieves the current Icon displayed on a label.

30) JLabel methods setHorizontalTextPosition and setVerticalTextPosition specify the text position in the label.

31) JFrame method setDefaultCloseOperation with constant JFrame.EXIT_ON_CLOSE as the argument indicates that the program should terminate when the window is closed by the user.

32) Component method setSize specifies the width and height of a component.

33) Component method setVisible with the argument TRue displays a JFrame on the screen.

34) GUIs are event drivenwhen the user interacts with a GUI component, events drive the program to perform tasks.

35) The code that performs a task in response to an event is called an event handler and the overall process of responding to events is known as event handling.

36) Class JTextField extends class JTextComponent (package javax.swing.text), which provides many features common to Swing's text-based components. Class JPasswordField extends JTextField and adds several methods that are specific to processing passwords.

37) A JPasswordField shows that characters are being typed as the user enters them, but hides the actual characters with echo characters.

38) A component receives the focus when the user clicks the component.

39) JTextComponent method setEditable can be used to make a text field uneditable.

40) Before an application can respond to an event for a particular GUI component, you must perform several coding steps: 1) Create a class that represents the event handler. 2) Implement an appropriate interface, known as an event-listener interface, in the class from Step 1. 3) Indicate that an object of the class from Steps 1 and 2 should be notified when the event occurs. This is known as registering the event handler.

41) Java allows you to declare nested classes inside other classes. Nested classes can be static or non-static. Non-static nested classes are called inner classes and are frequently used for event handling.

42) Before an object of an inner class can be created, there must first be an object of the top-level class that contains the inner class, because an inner-class object implicitly has a reference to an object of its top-level class.

43) An inner-class object is allowed to directly access all the instance variables and methods of its top-level class.

44) A nested class that is static does not require an object of its top-level class and does not implicitly have a reference to an object of the top-level class.

45) When the user presses Enter in a JTextField or JPasswordField, the GUI component generates an ActionEvent (package java.awt.event). Such an event is processed by an object that implements the interface ActionListener (package java.awt.event).

46) JTextField method addActionListener registers the event handler for a component text field. This method receives as its argument an ActionListener object.

47) The GUI component with which the user interacts is the event source.

48) An ActionEvent object contains information about the event that just occurred, such as the event source and the text in the text field.

49) ActionEvent method getSource returns a reference to the event source. ActionEvent method getActionCommand returns the text the user typed in a text field or the label on a JButton.

50) JPasswordField method getPassword returns the password the user typed.

51) For each event-object type, there is typically a corresponding event-listener interface. Each event-listener interface specifies one or more event-handling methods that must be declared in the class that implements the interface.

52) When an event occurs, the GUI component with which the user interacted notifies its registered listeners by calling each listener's appropriate event-handling method.

53) Every JComponent has an instance variable called listenerList that refers to an object of class EventListenerList (package javax.swing.event). Each object of a JComponent subclass maintains a references to all of its registered listeners in the listenerList.

54) Every GUI component supports several event types, including mouse events, key events and others. When an event occurs, the event is dispatched only to the event listeners of the appropriate type. The GUI component receives a unique event ID specifying the event type, which it uses to decide the listener type to which the event should be dispatched and which method to call on each listener object.

55) A button is a component the user clicks to trigger a specific action. All the button types are subclasses of AbstractButton (package javax.swing), which declares the common features of Swing buttons. Button labels typically use book-title capitalizationa style that capitalizes the first letter of each significant word in the text and does not end with any punctuation.

56) Command buttons are created with class JButton.

57) A JButton can display an Icon. To provide the user with an extra level of visual interaction with the GUI, a JButton can also have a rollover Iconan Icon that is displayed when the user positions the mouse over the button.

58) Method setRolloverIcon (of class AbstractButton) specifies the image displayed on a button when the user positions the mouse over it.

59) The Swing GUI components contain three types of state buttonsJToggleButton, JCheckBox and JRadioButton.

60) Classes JCheckBox and JRadioButton are subclasses of JToggleButton. A JRadioButton is different from a JCheckBox in that normally several JRadioButtons are grouped together, and only one in the group can be selected at any time.

61) Method setFont (of class Component) sets the font of a component to a new object of class Font (package java.awt).

62) When the user clicks a JCheckBox, an ItemEvent occurs. This event can be handled by an ItemListener object, which must implement method itemStateChanged. Method addItemListener registers the listener for a JCheckBox or JRadioButton object.

63) JCheckBox method isSelected determines if a JCheckBox is selected.

64) JRadioButtons are similar to JCheckBoxes in that they have two statesselected and not selected. However, radio buttons normally appear as a group in which only one button can be selected at a time. Selecting a different radio button forces all others to be deselected.

65) JRadioButtons are used to represent mutually exclusive options.

66) The logical relationship between JRadioButtons is maintained by a ButtonGroup object (package javax.swing).

67) ButtonGroup method add associates each a JRadioButton with a ButtonGroup. If more than one selected JRadioButton object is added to a group, the selected one that was added first will be selected when the GUI is displayed.

68) JRadioButtons generate ItemEvents when they are clicked.

69) A JComboBox provides a list of items from which the user can make a single selection. JComboBoxes generate ItemEvents.

70) Each item in a JComboBox has an index. The first item added to a JComboBox appears as the currently selected item when the JComboBox is displayed. Other items are selected by clicking the JComboBox, which expands into a list from which the user can make a selection.

71) JComboBox method setMaximumRowCount sets the maximum number of elements that are displayed when the user clicks the JComboBox. If there are additional items, the JComboBox provides a scrollbar that allows the user to scroll through all the elements in the list.

72) An anonymous inner class is a special form of inner class that is declared without a name and typically appears inside a method declaration. Since an anonymous inner class has no name, one object of the anonymous inner class must be created at the point where the class is declared.

73) JComboBox method getSelectedIndex returns the index of the selected item.

74) A JList displays a series of items from which the user may select one or more items. Class JList supports single-selection lists and multiple-selection lists.

75) When the user clicks an item in a JList, a ListSelectionEvent occurs. JList method addListSelectionListener registers a ListSelectionListener for a JList's selection events. A ListSelectionListener (package javax.swing.event) must implement method valueChanged.

76) JList method setVisibleRowCount specifies the number of items that are visible in the list.

74) JList method setSelectionMode specifies a list's selection mode.

75) A JList does not provide a scrollbar if there are more items in the list than the number of visible rows. In this case, a JScrollPane object can be used to provide the scrolling capability.

76) JFrame method getContentPane returns a reference to the JFrame's content pane where GUI components are displayed.

77) JList method getSelectedIndex returns the selected item's index.

78) A multiple-selection list enables the user to select many items from a JList.

79) JList method setFixedCellWidth sets a JList's width. Method setFixedCellHeight sets the height of each item in a JList.

80) There are no events to indicate that a user has made multiple selections in a multiple-selection list. Normally, an external event generated by another GUI component specifies when the multiple selections in a JList should be processed.

81) JList method setListData sets the items displayed in a JList. JList method getSelectedValues returns an array of Objects representing the selected items in a JList.

82) The MouseListener and MouseMotionListener event-listener interfaces are used to handle mouse events. Mouse events can be trapped for any GUI component that extends Component.

83) Interface MouseInputListener (package javax.swing.event) extends interfaces MouseListener and MouseMotionListener to create a single interface containing all their methods.

84) Each of the mouse event-handling methods takes a MouseEvent object as its argument. A MouseEvent object contains information about the mouse event that occurred, including the x- and y-coordinates of the location where the event occurred. These coordinates are measured from the upper-left corner of the GUI component on which the event occurred.

85) The methods and constants of class InputEvent (MouseEvent's superclass) enable an application to determine which mouse button the user clicked.

86) Interface MouseWheelListener enables applications to respond to the rotation of a mouse wheel.

87) GUI components inherit methods addMouseListener and addMouseMotionListener from class Component.

88) Many event-listener interfaces contain multiple methods. For many of these interfaces, packages java.awt.event and javax.swing.event provide event-listener adapter classes. An adapter class implements an interface and provides a default implementation of each method in the interface. You can extend an adapter class to inherit the default implementation of every method and subsequently override only the method(s) you need for event handling.

89) MouseEvent method getClickCount returns the number of mouse button clicks. Methods isMetaDown and isAltDown determine which mouse button the user clicked.

90) Lightweight Swing components that extend class JComponent contain method paintComponent, which is called when a lightweight Swing component is displayed. By overriding this method, you can specify how to draw shapes using Java's graphics capabilities.

91) When customizing a JPanel for use as a dedicated drawing area, the subclass should override method paintComponent and call the superclass version of paintComponent as the first statement in the body of the overridden method.

92) Subclasses of JComponent support transparency. When a component is opaque, paintComponent clears the component's background before the component is displayed.

93) The transparency of a Swing lightweight component can be set with method setOpaque (a false argument indicates that the component is transparent).

94) Class Point (package java.awt) represents an x-y coordinate.

95) Class Graphics is used to draw.

96) MouseEvent method getPoint obtains the Point where a mouse event occurred.

97) Method repaint (inherited indirectly from class Component) indicates that a component should be refreshed on the screen as soon as possible.

98) Method paintComponent receives a Graphics parameter and is called automatically any time a lightweight component needs to be displayed on the screen.

99) Graphics method fillOval draws a solid oval. The method's four parameters represent the bounding box in which the oval is displayed. The first two parameters are the upper-left x-coordinate and the upper-left y-coordinate of the rectangular area. The last two coordinates represent the rectangular area's width and height.

100) Interface KeyListener is used to handle key events that are generated when keys on the keyboard are pressed and released. Method addKeyListener of class Component registers a KeyListener for a component.

101) KeyEvent method getKeyCode gets the virtual key code of the key that was pressed. Class KeyEvent maintains a set of virtual key-code constants that represent every key on the keyboard.

102) KeyEvent method getKeyText returns a string containing the name of the key that was pressed.

103) KeyEvent method getKeyChar gets the Unicode value of the character typed.

104) KeyEvent method isActionKey determines whether the key in an event was an action key.

105) InputEvent method getModifiers determines whether any modifier keys (such as Shift, Alt and Ctrl) were pressed when the key event occurred.

106) KeyEvent method getKeyModifiersText produces a string containing the names of the pressed modifier keys.

107) Layout managers arrange GUI components in a container for presentation purposes.

108) All layout managers implement the interface LayoutManager (package java.awt).

109) Container method setLayout specifies the layout of a container.

110) FlowLayout is the simplest layout manager. GUI components are placed on a container from left to right in the order in which they are added to the container. When the edge of the container is reached, components continue to display on the next line. Class FlowLayout allows GUI components to be left aligned, centered (the default) and right aligned.

111) FlowLayout method setAlignment changes the alignment for a FlowLayout.

112) The BorderLayout layout manager (the default for a JFrame) arranges components into five regions: NORTH, SOUTH, EAST, WEST and CENTER. NORTH corresponds to the top of the container.

113) A BorderLayout limits a Container to containing at most five componentsone in each region.

114) The GridLayout layout manager divides the container into a grid so that components can be placed in rows and columns.

115) Container method validate recomputes a container's layout based on the current layout manager for the Container and the current set of displayed GUI components.

116) A JTextArea provides an area for manipulating multiple lines of text. JTextArea is a subclass of JTextComponent, which declares common methods for JTextFields, JTextAreas and several other text-based GUI components.

117) Class Box is a subclass of Container that uses a BoxLayout layout manager to arrange the GUI components either horizontally or vertically.

118) Box static method createHorizontalBox creates a Box that arranges components from left to right in the order that they are attached.

119) Method getSelectedText (inherited into JTextArea from JTextComponent) returns the selected text from a JTextArea.

120) You can set the horizontal and vertical scrollbar policies of a JScrollPane when it is constructed. JScrollPane methods setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy can be used change the scrollbar policies at any time.

About the Authors

Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.

Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of the MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered Java, C, C++, Internet and World Wide Web courses to industry clients, including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, Compaq, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, Open Environment Corporation, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the most experienced Java corporate trainers having taught about 100 professional Java training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.

1 comment:

Anonymous said...

If you desire to obtain a great deal from this piece of writing then you have to apply such strategies to
your won weblog.

Here is my weblog; automatic forex trading software
My webpage :: research penny Stocks