1 / 9

Swing 101

Swing 101. If you get lost - Important Links. Swing articles: http :// java.sun.com/javase/technologies/desktop/articles.jsp Swing Architecture: http://java.sun.com/products/jfc/tsc/articles/architecture / Visual Editor for Eclipse: http:// wiki.eclipse.org/VE/Update#Online_Install

lydie
Download Presentation

Swing 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Swing 101

  2. If you get lost - Important Links • Swing articles:http://java.sun.com/javase/technologies/desktop/articles.jsp • Swing Architecture:http://java.sun.com/products/jfc/tsc/articles/architecture/ • Visual Editor for Eclipse:http://wiki.eclipse.org/VE/Update#Online_Install • Oracle Swing tutorial:http://download.oracle.com/javase/tutorial/uiswing/ • Stack Overflow:http://stackoverflow.com/ • Basic Swing tutorial: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 themThe 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# • Components • http://download.oracle.com/javase/tutorial/ui/features/compWin.html • Layout • http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

More Related