Download presentation
Presentation is loading. Please wait.
Published byGillian Carpenter Modified over 9 years ago
1
SWING 101
2
IF YOU GET LOST - IMPORTANT LINKS Swing articles: http://java.sun.com/javase/technologies/desktop/articles.jsp http://java.sun.com/javase/technologies/desktop/articles.jsp Swing Architecture: http://java.sun.com/products/jfc/tsc/articles/architecture/ http://java.sun.com/products/jfc/tsc/articles/architecture/ Visual Editor for Eclipse: http://wiki.eclipse.org/VE/Update#Online_Install http://wiki.eclipse.org/VE/Update#Online_Install Oracle Swing tutorial: http://download.oracle.com/javase/tutorial/uiswing/ http://download.oracle.com/javase/tutorial/uiswing/ Stack Overflow: http://stackoverflow.com/ http://stackoverflow.com/ Basic Swing tutorial: http://zetcode.com/tutorials/javaswingtutorial/ http://zetcode.com/tutorials/javaswingtutorial/
3
SWING - HISTORY UI Platform specific AWT (Advanced Windows Toolkit) was platform specific Delegated creation of UI components to the OS Heavy Not customizable Swing - Part of the JFC (Java Foundation Classes) Extends (some of) AWT Draws its own components Light weight Very customizable All classes start with ‘J’ (JPanel, JButton, etc.)
4
UI FRAMEWORKS CONCEPTS Events A way for components (in general) to communicate with each other asynchronously (meaning, without directly calling methods on each other or using polling) In java, it simply means that you register an interface (usually called a Listener) to an event generator and when an event generator wants to notify all the registered listeners it iterates over them calls methods define in them The parameter passed to the interface methods is an called an Event object MVC (Model – View – Controller) A model that represents the data for the application The view that is the visual representation of that data A controller that takes user input on the view and translates that to changes in the model
5
UI FRAMEWORKS CONCEPTS UI runs in another thread called the EDT (Event Dispatch Thread) This is done in order to make the UI responsive Separate UI code from Business Logic code User code can run in the EDT, but for long loops and actions (like network operations, database operations, etc.) it is usually preferred to run the code in another thread In order to run a code in the EDT (after a thread has finished its work) use: SwingUtilities.invokeLater()
6
(J)COMPONENT IN SWING JComponents (extends Container) JButton, JLabel, JTable, JTree, JCheckBox, etc. Containers Components that groups other components and other containers Can be used with Layout Manager to automatically set the size and location of their child components Top Level Containers The root objects for swing application At least one is mandatory for the application to start JFrame, JDialog, JApplet, JWindow
7
(J)COMPONENT IN SWING JComponents have the following capabilities: Properties (such as color, preferred size) Methods (for getting and setting data like setText(), etc.) Events (a component might send more that one type of event)
8
(J)COMPONENT IN SWING All the components (from AWT or from Swing) have properties that changes how the component looks and behaves You can register different types of Event Listeners to a component in order to receive events from it (for example: MouseEvent on a JPanel, ChangeEvent on a JCheckBox, etc.) Some components have several Models in them for different data: a JList component have a Selection Model that represents the current selected items in the component (and you can register a listener for that as well) All components have a ‘paintComponent’ method that actually tell the JVM how to draw the component. Overwriting this method is done for advanced cases…
9
SWING COMPONENTS HIERARCHY Tutorial http://www.docstoc.com/docs/33446046/Java-Swing# http://www.docstoc.com/docs/33446046/Java-Swing# Components http://download.oracle.com/javase/tutorial/ui/features/compWin.html http://download.oracle.com/javase/tutorial/ui/features/compWin.html Layout http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.