Swing Application Framework and Beans Binding David Botterill

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Java Tutorial – Building GUIs Java with Added Swing Daniel Bryant
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Writing GUI Applications An introduction with Java.
Object-Oriented Software Engineering Java with added Swing.
Graphical User Interfaces
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
Java Swing Joon Ho Cho. What is Java Swing? Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
UNIT-V The MVC architecture and Struts Framework.
Creating of Rich Client Applications using NetBeans 6 and Java Swing Miroslav Nachev.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Graphical User Interface (GUI) Design using Swing Course Lecture Slides.
Written by Liron Blecher
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Saldin Samuel eBay India Product Center 29 th October 2010.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Java GUI Framework Developed for Tantivy EMS System (October 1999 to August 2000)
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Review_6 AWT, Swing, ActionListener, and Graphics.
Java Swing One of the most important features of Java is its ability to draw graphics.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
GUI 1: JFC and Swing Basics OOP tirgul No
Module 13: Swing API Object Oriented Programming(Java)
Using NetBeans IDE for Desktop Development Geertjan Wielenga
Beans Binding Framework & Swing Application Framework Geertjan Wielenga http//netbeans.dzone.com.
Presenter Name This presentation introduces Swing Application Framework and Beans Binding JSRs. These are two new JSRs which greatly.
Welcome To java
Recap Modules: dependency management, revisioning, information hiding
Geertjan Wielenga
“Form Ever Follows Function” Louis Henri Sullivan
Lecture 27 Creating Custom GUIs
Geertjan Wielenga This presentation introduces Swing Application Framework and Beans Binding JSRs. These are two new JSRs.
A Quick Java Swing Tutorial
Productivity Tools Extensions to NetBeans IDE that make life easier
Introduction to Graphical Interface Programming in Java
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Swing Application Framework and Beans Binding David Botterill

2 Agenda ● Introduction ● JSR 296 (Swing App. Framework) ● JSR 295 (Beans Binding) ● Putting it all together ● Conclusion

3 ● Goals of this session: ● Introduce new JSRs for desktop Java: JSR 296 and 295 ● Demonstrate building an application using these frameworks Introduction

4 Agenda ● Introduction ● JSR 296 (Swing App. Framework) ● JSR 295 (Beans Binding) ● Putting it all together ● Conclusion

5 ● Swing v 0.1 debuts in 1997 ● It's widely adopted now ● But there is no standard framework Swing App. Framework

6 public static void main(String args[]) { // good luck! } Motivation

7 ● Goals: ● As small as possible ● Explain it all in an hour ● Work well for small/medium apps ● Nice consequence: toolable ● Out of scope: ● Modular system, docking, filesystems, data models, help system, updates, etc. ● Not a replacement for NetBeans platform Framework Goals

8 ● Lifecycle support ● Resources ● Actions ● Tasks ● Session state Framework Features

9 Framework Architecture

10 import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame("HelloWorldSwing"); final JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } Lifecycle Support Without

11 public class MyApp extends SingleFrameApplication protected void startup() { JLabel label = new JLabel("Hello World"); show(label); } public static void main(String[] args) { Application.launch(MyApp.class, args); } // SingleFrameApplication is a subclass of Application Lifecycle Support

12 Lifecycle Support Calls initialize(), startup(), ready() on EDT thread. Performs initializations that must happen before the GUI is created like setting look & feel. Creates the initial GUI and shows it. All applications will override this method. Any work that must wait until the GUI is visible and ready for input. Calls shutdown() if the exitListeners do not veto. Main frame's Windowlistener calls exit(). Take the GUI down and do final cleanup.

13 ● Defined with regular ResourceBundles ● ResourceManager class is used ● Three options: ● Manually load, use ResourceMap objects ● Automatically inject resources into UI components ● Automatically inject resources into object fields Resources

14 # resources/MyForm.properties aString = Just a string aMessage = Hello {0} anInteger = 123 aBoolean = True anIcon = myIcon.png aFont = Arial-PLAIN-12 colorRGBA = 5, 6, 7, 8 color0xRGB = # ApplicationContext c = Application.getContext(MyForm.class).getInstance(); ResourceMap r = c.getResourceMap(MyForm.class); r.getString("aMessage", "World") => "Hello World" r.getColor("colorRBGA") => new Color(5, 6, 7, 8) r.getFont("aFont") => new Font("Arial", Font.PLAIN, 12) Manual Loading

15 Resource file: btnShowTime.text = Show current time! btnShowTime.icon = refresh.png Java class: btnShowTime = new JButton(); txtShowTime = new JTextField(); btnShowTime.setName("btnShowTime"); txtShowTime.setName("txtShowTime"); Resource Injection ● Resources are injected automatically!

16 Resource file: MyPanel.greetingMsg = Hello, %s, a string was injected! Java String greetingMsg; ResourceMap resource = ctxt.getResourceMap(MyPanel.class); resource.injectFields(this); String personalMsg = String.format(greetingMsg, txtName.getText()); JOptionPane.showMessageDialog(this, personalMsg); Object Field Injection

17 Let's Look at Some Code Resources

18 ● Instead of ActionListeners ● Asynchronous actions are easy annotation ● Possible simple = "changesPending") public void save() {... } public boolean getChangesPending() {... } Actions

19 // define sayHello Action – pops up message public void sayHello() { String s = textField.getText(); JOptionPane.showMessageDialog(s); } // use sayHello – set the action property Action sayHello = Application.getContext(). getActionMap(MyForm.class, this).get("sayHello"); textField.setAction(sayHello); button.setAction(sayHello); Actions

20 Let's Look at Some Code Actions

21 ● Inherit the SwingWorker API ● Support for monitoring ● Title, Start/Done, etc. ● return Tasks ● Easy to handle non-blocking actions Tasks

22 ● Easily save properties: ● Window size ● Application position ● Sizes of columns in jTable, etc. ● ApplicationContext.getSessionStorage() ● SessionStorage.save(RootComponent, filename) ● Default for SingleFrameApplication is windowname + “.session.xml” ● Uses XMLEncoder & XMLDecoder Session State

23 ● JSR 296 vs. NetBeans Platform ● Platform is better for: ● Applications that can reuse platform APIs ● Editor-based applications ● If you need update centers, window system, file systems, data systems, help system, visual designers, explorers, etc. ● JSR 296 is much easier to learn JSR 296 vs. NB Platform

24 ● When will JSR-296 be in a JDK? ● Planned - Java Platform 7 ● I can't wait. Where can I get it? ● Packaged with NetBeans 6 (version 1.0) ● Source available as a NetBeans project at When and Where?

25 Demo JSR Flickr Demo

26 Agenda ● Introduction ● JSR 296 (Swing App. Framework) ● JSR 295 (Beans Binding) ● Putting it all together ● Conclusion

27 Beans Binding ● Keeps two properties of two objects in sync ● Source properties can specified using Expression Language: ● ex: “${customer}” or “${employee.salary}” ● Does not require special object types: ● Bindings.createAutoBinding(READ_WRITE,source,sou rce Prop, target, target Prop);

28 Builds Upon... ● JavaBeans ● PropertyChangeListeners ● Doesn't require strict following of spec ● Collection classes ● Standard way to encapsulate common data types

29 Features ● Different update strategies ● Read once, read only from source, keep source and target in sync ● Ability to do validation ● Ability to transform value ● String to Color, Date to String

30 Binding

31 Example

32 Example

33 Example

34 Example

35 faceSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { caricature.setFaceStyle(faceSlider.getValue()); } }); caricature.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName() == “faceStyle”) { faceSlider.setValue(caricature.getFaceStyle()); } } }); Example - Before 295

36 Property faceStyleP = ELProperty.create(“${faceStyle}”); BeanProperty valueP = BeanProperty.create(“value”); Binding binding = new Binding(READ_WRITE, caricature, faceStyleP, // source faceSlider, valueP); // target binding.bind(); Example - JSR 295

37 Let's Look at Some Code Binding

38 Demo JSR Ticker Demo

39 ● When will JSR-295 be in a JDK? ● Planned - Java Platform 7 ● I can't wait. Where can I get it? ● Version in NetBeans 6 m10 ● Version 1.0 ● Released Sept. 5, 2007 ● Available at When and Where?

40 Agenda ● Introduction ● JSR 296 (Swing App. Framework) ● JSR 295 (Beans Binding) ● Putting it all together ● Conclusion

41 Demo JSR JSR Matisse improvements in NB 6.0

42 Conclusion ● JSR 295 and 296 are making Swing development fun again ● Both are very well supported in NetBeans GUI builder (project Matisse) ● Desktop Java becoming interesting for “Delphi” and “VB” developers ● Desktop Java is well and alive!

Swing Application Framework and Beans Binding