01 Java Is Architecture Neutral


Published on

Published in: Technology, Education
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

01 Java Is Architecture Neutral

  1. 1. Architecture Dependent /* My first C program. */ #include <stdio.h> Main() { Printf(“Hello World!”); } Platform independent C source code C compiler for Sun Solaris C compiler for Windows C compiler for Mac OS C compiler for Linux Compilation Yields 10010110011101101001010101001010 10110101011001010111010101111101 01010100101010101011101010001001 10101011110011101000101001011100 Platform specific binary code
  2. 2. Java Architecture Neutral // My first Java program. public class HelloWorld { public static void main (String[ ] args) { System.out.println(“Hello World!”); } } Platform independent java source code Compilation Yields E po 3/4 -   () V  ([Ljava/lang/String;)V <init> Code HelloWorld HelloWorld.java…………. Platform independent byte code A platform DEPENDENT JVM running on the underlying Hardware architecture 101010010100100101001010010010100011010001010010001000001001010001010010 Binary code java compiler for Sun Solaris java compiler for Windows Java compiler for Mac OS Java compiler for Linux
  3. 3. Hierarchical diagram Dimension Font FontMetrics Color Graphics Component LayoutManager Container Panel Window Applet Frame Dialog JApplet JFrame JDialog JComponent 1 ** Classes in the java.awt package Swing Components in the javax.swing package HeavyWeight LightWeight
  4. 4. JComponent and its subclasses AbstractButton JTextComponent JMenuItem JButton JToggleButton JEditorPane JTextField JTextArea JCheckBoxMenuItem Jmenu JRadioButtonMenuItem JCheckBox JRadioButton JPasswordField JLabel JList JComboBox JMenuBar JPanel JOptionPane JScrollBar JScrollPane JFileChooser JPopupMenu JProgressBar JInternalFrame JSeparator JToolbar JToolTip JSlider JSplitPane JLayeredPane JTabbedPane JTable JTableHeader JRootPane JTree JPane JColorChooser JComponent
  5. 5. EventObject Class AWTEvent ListSelectionEvent ActionEvent AdjustmentEvent ComponentEvent ItemEvent TextEvent ContainerEvent FocusEvent InputEvent PaintEvent WindowEvent EventObject MouseEvent KeyEvent
  6. 6. Event Registration, Listening and Handling Register a Listener object Source Object Event Object Event Handler Listener Object Trigger an Event Generate an Event Generate an Event An event triggered by user actions on the source objects. The source object generates the event object and invokes the handler of the listener object to process the event. User action
  7. 7. Graphical user interface: Application Frame Pull-down Menus A frame can contain menus, panels, and user interface components. Panels can contain other panels. Panel Panel Panel UI Panel UI Panel UI Panel UI User Interface Components (UI)
  8. 8. Graphical user interface: Applet Applet Pull-down Menus A frame can contain menus, panels, and user interface components. Panels can contain other panels. Panel Panel User Interface Component Panel User Interface Component Panel Panel Panel User Interface Component Panel Panel User Interface Component Panel User Interface Component Panel Panel User Interface Component Panel Panel
  9. 9. UserAction, SourceObject and EventType MouseEvent Component Mouse pressed, released, moved, clicked, entered, or exited KeyEvent Component Key released or pressed ListSelectionEvent JList Select Item(s) AdjustmentEvent JScrollBar Move the scroll bar WindowEvent Window Window open, close,closing, iconified,de-iconified ContainerEvent Container Component added/removed ComponentEvent Component Component moved, resized, hidden or shown TextEvent JTextComponent Change text FocusEvent Component Component gained or lost focus ItemEvent, ActionEvent JRadioButton Click a radio button ItemEvent, ActionEvent JCheckBox Click a check box ItemEvent, ActionEvent JComboBox Select a new item ActionEvent JMenuItem Select menu item ActionEvent JTextField <cr> on a text field ActionEvent JButton Click a button Event Type generated Source Object User Action
  10. 10. Events, EventListener and Listener Methods componentMoved(ComponentEvent e) componentHidden(ComponentEvent e) componentResized(ComponentEvent e) componentShown(ComponentEvent e) ComponentListener ComponentEvent componentAdded(ContainerEvent e) componentRemoved(ContainerEvent e) ContainerListener ContainerEvent focusGained(FocusEvent e) focusLost(FocusEvent e) FocusListener FocusEvent keyPressed(KeyEvent e) keyReleased(KeyEvent e) keyTyped(KeyEvent e) KeyListener KeyEvent adjustmentValueChanged (AdjustmentEvent e) AdjustmentListener AdjustmentEvent textValueChanged(TextEvent e) TextListener TextEvent itemStateChanged(ItemEvent e) ItemListener ItemEvent ActionPerformed(ActionEvent e) ActionListener ActionEvent Listener Methods (handlers) Listener Interface Event Class
  11. 11. Events, EventListener and Listener Methods windowClosing(WindowEvent e) windowOpened(WindowEvent e) windowIconfied(WindowEvent e) windowDeIconified(WindowEvent e) windowClosed(WindowEvent e) windowActivated(WindowEvent e) windowDeactivated(WindowEvent e) WindowListener WindowEvent mousePressed(MouseEvent e) mouseReleased(MouseEvent e) mouseEntered (MouseEvent e) mouseExited (MouseEvent e) mouseClicked (MouseEvent e) mouseDragged (MouseEvent e) mouseMoved (MouseEvent e) MouseListener MouseMotionListener MouseEvent Listener Methods (handlers) Listener Interface Event Class