Swing vs AWT When Java was introduced, the gui classes were bundled in a library known as the abstract Windows Toolkit(AWt). For every platform on which Java runs, the awT components are automatically mapped to the platform-specific components through their respective agents, known as peers. AWT is fine for developing simple graphical user interfaces, but not for developing comprehensive GuI projects O AWT is prone to platform-specific bugs because its peer-based approach relies heavily on the underlying platform Swing components are painted directly on canvases using Java code except for components that are subclasses of java. awt. Window or java.awt. Panel, which must be drawn using native gui on a specific platform Swing components are less dependent on the target platform and use less of the native gui resource o For this reason, Swing components that don' t rely on native GUI are referred to as lightweight components, and awT components are referred to as heavyweight components Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 Swing vs. AWT ⚫When Java was introduced, the GUI classes were bundled in a library known as the Abstract Windows Toolkit (AWT). For every platform on which Java runs, the AWT components are automatically mapped to the platform-specific components through their respective agents, known as peers. ⚫AWT is fine for developing simple graphical user interfaces, but not for developing comprehensive GUI projects. ⚫AWT is prone to platform-specific bugs because its peer-based approach relies heavily on the underlying platform. ⚫ Swing components are painted directly on canvases using Java code, except for components that are subclasses of java.awt.Window or java.awt.Panel, which must be drawn using native GUI on a specific platform. ⚫Swing components are less dependent on the target platform and use less of the native GUI resource. ⚫For this reason, Swing components that don’t rely on native GUI are referred to as lightweight components, and AWT components are referred to as heavyweight components
GUI Class Hierarchy(Swing) Dimension Classes in the java.awt Layout manage Font Fontmetrics Object Color 匚Pa-K[ Applet Khi JApplet Graphics Component Container K Window KI Frame Jframe Dialog Kh JDialog JComponent in the javax. swing package Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 GUI Class Hierarchy (Swing) Dimension Font FontMetrics Component Graphics Object Color Container Panel Applet Frame Dialog Window JComponent JApplet JFrame JDialog Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager *
Container classes Dimension Classes in the java.awt Layout Manager Heavier Font FontMetrics Object Color Panel Applet K JApplet Graphics Component K Container Window KI Frame JFrame Dialog JDialog COmponen JPanel Container classes can in the javax. swing package contain other gui components Lightweight Liang, Introduction to Java Programming, revise
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 Container Classes Dimension Font FontMetrics Component Graphics Object Color Container Panel Applet Frame Dialog Window JComponent JApplet JFrame JDialog Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager * JPanel Container classes can contain other GUI components
GUI Helper Classes Dimension Classes in the java. awt Layout Manager package Heavyweight Font FontMetrics O Color 匚 Panel[Apk{ Japplet Graphi I Component K Container Window K Frame Jframe Dialog JDialog The helper classes are not ar Swing Components subclasses of Component opponet in the javax. swing package They are used to describe the properties of gui components Lightweight such as graphics context colors, fonts, and dimension. tion to Java Programming, revised by dai
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 GUI Helper Classes Dimension Font FontMetrics Component Graphics Object Color Container Panel Applet Frame Dialog Window JComponent JApplet JFrame JDialog Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager * JPanel The helper classes are not subclasses of Component. They are used to describe the properties of GUI components such as graphics context, colors, fonts, and dimension
Swing GUI Components J Check BoxMenultem JMenultem KHJMenu abstract Butto Button J Radio Button Menuitem JToggleButton KhTICheckBox. JRadioButton Component JEditorPane] JTex Component KH JText Fiels画swde TextArea JLabel DList COmbo Box] JPanel JOptionPane] [ScrollBar JSlider] JTabbedPaneJSplitPanejLayeredPane SEparator[JScrollPane jRootPane ToolBar] DMenuBar] [PopupMenu JFileChooser] JColorChooser Tool JT JTable JTableheade Internal FrameJProgressB Spinner -tang:introduction tordavar Trogrammimgreviseu by Dai-ktar
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 Swing GUI Components JMenuItem JCheckBoxMenuItem AbstractButton JComponent JMenu JRadioButtonMenuItem JToggleButton JCheckBox JRadioButton JComboBox JInternalFrame JLayeredPane JList JMenuBar JOptionPane JPopupMenu JProgressBar JFileChooser JScrollBar JSeparator JScrollPane JSplitPane JSlider JTabbedPane JTable JTableHeader JTextComponent JTextField JTextArea JToolBar JToolTip JTree JRootPane JPanel JPasswordField JColorChooser JLabel JEditorPane JSpinner JButton