1、Java Swing,Joon Ho Cho,What is Java Swing?,Part of the Java Foundation Classes (JFC)Provides a rich set of GUI componentsUsed to create a Java program with a graphical user interface (GUI)table controls, list controls, tree controls, buttons, and labels, and so on,What features are available?,GUI co
2、mponents like button, checkbox, and so onJava 2D API: images, figures, animation Pluggable look and feel: use samples or create your ownData Transfer: cut, copy, paste, drag & dropInternationalization: supports different input language, right to left readingAccessibility API: for people with disabil
3、itiesUndo Framework API: supports unlimited numbers of actions to undo and redoFlexible Deployment: run within a browser as an applet or Java Web Start,How does HelloWorld look like?,import javax.swing.*; public class HelloWorldSwing private static void createAndShowGUI() /Create and set up the wind
4、ow. JFrame frame = new JFrame(HelloWorldSwing); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /Add the ubiquitous Hello World label. JLabel label = new JLabel(Hello World); frame.getContentPane().add(label); /Display the window. frame.pack(); frame.setVisible(true); public static void main(S
5、tring args) /Schedule a job for the event-dispatching thread: /creating and showing this applications GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() public void run() createAndShowGUI(); ); ,Who are users?,Since we are evaluating user interface toolkit itself, in this case Java Swing, us
6、ers will be software developers, not software usersI believe that most Java developers use Eclipse as their developing platform so we will evaluate Java Swing with Eclipse based on ten usability heuristics by Jakob Nielson,1. Visibility of system status,This may be a strong advantage of Java Swing o
7、ver other UI toolkits, not because of Java Swing itself is great, but because Eclipse provides such sophisticated checking on what is going on nowConstantly checks for syntax errorsLists available methods or variables when press . (dot)However, you dont have synchronous result viewYou will have to r
8、un it in order to see the status of your program,2. Match between system and the real world,First of all, it is JavaIt follows Java conventionIt consists of 18 public packages of Java classesIts classes and methods are reasonably namedUnless you are the first time programmer, you dont have to worry
9、about its syntax or conventionJLabel developerNameLabel = new javax.swing.JLabel();developerNameLabel.setFont(new java.awt.Font(Arial, 0, 14);developerNameLabel.setForeground(new java.awt.Color(255, 255, 255);,3. User control and freedom,Eclipse supports strong undo and redo featuresYou cant possibl
10、y go wrong and have to rewrite every codeYou can always fix it even though it may take you some effort and timeJava Swing also provides undo and redo packagejavax.swing.event.UndoableEditEvent;javax.swing.event.UndoableEditListener;javax.swing.undo.UndoableEdit;,4. Consistency and standards,Similar
11、to #2Java Swing follows Java conventionPackages, classes, methods, parameters, variablesMainly constructor, getter, setter,5. Error prevention,First of all, Java is a strongly typed language: primitives and objectsEclipse checks for syntax and type errors continuouslyIt gives red underline to errors
12、 and small red box to let you know which line in document it is locatedIf you move your mouse over the error, then it suggests possible solutions to the errorIf you think one of the suggestions is a solution, then simply click on it to apply itOf course, it wont compile and run until you fix all the
13、 syntax errorsHowever, you dont have any idea about runtime errors except that you will have to run it and find out,6. Recognition rather than recall,Its a programming language, so its better and faster for you if you memorize names and their functions of classes or methodsHowever, whenever you pres
14、s dot after name of package, class, or object, then eclipse provides you a list of all possible subclasses, functions and variablesIf you move your mouse over almost anything, then eclipse provides you with a text document associated with it, usually javadoc, or you can click on it and it directs yo
15、u to online javadoc pageYou dont have a help of graphical interface to develop a graphical interface, so it maybe a disadvantage of Java Swing with eclipse.By the way, you can have a graphical interface if you use NetBeans IDE instead of eclipse,7. Flexibility and efficiency of use,Swing includes ma
16、ny basic components as a package, so it is efficient to use themAt the same time, you can create almost anything you want as combination of those components and some pure coding in JavaJava have had a reputation for being slower and requiring more memory than those written in natively compiled langu
17、ages such as C or C+However, the performance heavily depends on how you optimize your codes and which components of UI you use the most frequentlyIt may be subsequently slower or faster,8. Aesthetic and minimalist design,Swing is designed in a way that it provides a set of lightweight (all-Java lang
18、uage) components that, to the maximum degree possible, work the same on all platformsIt includes almost only and all components we could find around any software with user interfaceYet, it gives developers varieties to customize those components,9. Help users recognize, diagnose, and recover from er
19、rors,Syntax and type checking errors are already covered previouslyJava shows where in the code runtime errors (exceptions) are caused, specifying line numbers and brief reason for error on the console of eclipseIts not always right, but most of the times it is rightIts relatively easy to find the c
20、ause of the error and debug it comparing to other languages I have experienced with,10. Help and documentation,JavadocEclipses support for javadoc (already covered),Conclusion,Java Swing is easier to learn than others because its JavaYou can use any helpful tools out there that are for Java development like eclipse IDE, NetBeans IDELacks live graphical and interactive help while developingHas unlimited possibilities depending on how you implement your software,