Download presentation
Presentation is loading. Please wait.
Published byChristal Hardy Modified over 8 years ago
1
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements (IOC) AWT/SWT AWT/SWT ”Heavyweight” Layer of abstraction over native GUI calls Looks like native applications Swing Uses Graphics2D to 'draw' components on the screen Uses the 'Look and Feel' manager to determine the appearance of the GUI. System invariant
2
Class Structure Every class in swing is a Component. Each class follows the following structure (except for top level containers) java.lang.Object java.awt.Component java.awt.Container java.awt.JComponent javax.swing.* This structure allows for Nesting containers within containers Each component can implement its own look
3
Division of Components Containers, Displays, Input Top Level Containers JApplet, JDialog, JFrame
4
Division of Components General Purpose Containers JPanel, JScrollPane, JToolBar...
5
Division of Components Basic Controls (Input) JButton, JCheckBox, JTextField, JMenu...
6
Division of Components Interactive Display JTable, JFileChooser, JTextArea, JTree...
7
Division of Components Uneditable Information Displays JLabel, JProgressBar, JSeparator
9
Look and Feel Swing does not rely on native GUI calls Draws all GUI components with own libraries Look and Feel choice defines presentation
10
Layout Manager Programming vs. Layout Design Built in Layouts help provide solutions for various simple GUI scenarios I need to display some buttons in a row I need to display elements in a grid I need elements to expand if they get bigger I need there to be a constant spacing I have many components which need to be placed in arbitrary locations I want my components to move as the window is resized
11
Layout Manager Examples
13
Event Handlers How does Swing handle input events? Components require Listeners and Handlers to execute code when an input has been received Examples: MouseListener, KeyListener Event objects contain information about the event such as (x,y) loc, Button Pressed, Keyboard key pressed A function is defined which is to be performed upon the event happening (ActionEvent)
14
Graphics & Animation Graphics can be drawn in real time Graphics2D has many built in draw functions DrawLine, Primitives, Fill, SetPaint Implemented as a Component which can be added like any other element of Swing Animation can be achieved by implementing the component as a thread, and redrawing with updated parameters
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.