Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
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.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
GUI Programming in Java
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Software Construction Lecture 10 Frameworks
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Creating GUIs in Java Using.
Objectives of This Session
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
GUI development in Java L. Grewe Two methodologies for things to appear on the screen 1. By painting / drawing e.g. drawing an Image e.g. drawing an.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
CS Lecture 00 Swing overview and introduction Lynda Thomas
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.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
Object Oriented programming Instructor: Dr. Essam H. Houssein.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
Applets Yong Choi School of Business CSU, Bakersfield.
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.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Review_6 AWT, Swing, ActionListener, and Graphics.
Basics of GUI Programming Chapter 11 and Chapter 22.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 14 JavaFX Basics.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Designing a User Interface with Swing Assignment Swing: Update code of an earlier program.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
A Quick Java Swing Tutorial
Welcome To java
Provision for GUIs in Java
A First Look at GUI Applications
University of Central Florida COP 3330 Object Oriented Programming
Designing a User Interface with Swing
Java Look-and-Feel Design Guidelines
Provision for GUIs in Java
Swing & the JFC – Advanced Java GUI
Ellen Walker Hiram College
Introduction to Graphical Interface Programming in Java
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Week 8 Swing NetBeans GUI Builder
Chapter 12 GUI Basics.
Graphical User Interface
Presentation transcript:

Session 27 Swing vs. AWT

AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window Toolkit provides the connection between your application and the native GUI. AWT features include: –A rich set of user interface components. –A robust event-handling model. –Graphics and imaging tools, including shape, color, and font classes. –Layout managers, for flexible window layouts that don't depend on a particular window size or screen resolution. –Data transfer classes, for cut-and-paste through the native platform clipboard. –The AWT components depend on native code counterparts (called peers) to handle their functionality. Thus, these components are often called "heavyweight" components.

Swing Swing implements a set of GUI components that build on AWT technology and provide a pluggable look and feel. Swing is implemented entirely in the Java programming language, and is based on the JDK 1.1 Lightweight UI Framework. Swing features include: –All the features of AWT. –100% Pure Java certified versions of the existing AWT component set (Button, Scrollbar, Label, etc.). –A rich set of higher-level components (such as tree view, list box, and tabbed panes). –Pure Java design, no reliance on peers. –Pluggable Look and Feel. –Swing components do not depend on peers to handle their functionality. Thus, these components are often called "lightweight" components.

AWT Pros and Cons Pros Speed: use of native peers speeds component performance. Applet Portability: most Web browsers support AWT classes so AWT applets can run without the Java plugin. Look and Feel: AWT components more closely reflect the look and feel of the OS they run on. Cons Portability: use of native peers creates platform specific limitations. Some components may not function at all on some platforms. Third Party Development: the majority of component makers, including Borland and Sun, base new component development on Swing components. There is a much smaller set of AWT components available, thus placing the burden on the programmer to create his or her own AWT-based components. Features: AWT components do not support features like icons and tool-tips.

Swing Pros and Cons Pros Portability: Pure Java design provides for fewer platform specific limitations. Behavior: Pure Java design allows for a greater range of behavior for Swing components since they are not limited by the native peers that AWT uses. Features: Swing supports a wider range of features like icons and pop-up tool- tips for components. Vendor Support: Swing development is more active. Sun puts much more energy into making Swing robust. Look and Feel: The pluggable look and feel lets you design a single set of GUI components that can automatically have the look and feel of any OS platform (Microsoft Windows, Solaris, Macintosh, etc.). It also makes it easier to make global changes to your Java programs that provide greater accessibility (like picking a hi-contrast color scheme or changing all the fonts in all dialogs, etc.). Cons Applet Portability: Some Web browsers do not include the Swing classes, so the Java plugin must be used. Performance: Swing components are generally slower and buggier than AWT, due to both the fact that they are pure Java and due to video issues on various platforms. Since Swing components handle their own painting (rather than using native API's like DirectX on Windows) you may run into graphical glitches. Look and Feel: Even when Swing components are set to use the look and feel of the OS they are run on, they may not look like their native counterparts.

AWT vs. Swing In general, AWT components are appropriate for simple applet development or development that targets a specific platform (i.e. the Java program will run on only one platform). For most any other Java GUI development you will want to use Swing components. Whether you choose to use Swing or AWT for your Java program development, you should avoid mixing the two. There are many painting problems that can occur when you mix heavyweight AWT components with lightweight Swing.

Converting between AWT and Swing Import javax.swing.* and javax.swing.event.* Corresponding Swing components are the same name as AWT, except: –‘J’ prepended to the name: JButton, JPane, etc. –Scrollbar in AWT became JScrollBar Swing implemented many new components and some new methods, but is generally backwards compatible with AWT

Adding Components to a Window Swing requires you to invoke the getContentPane() method before adding the component using the add() method. public class CannonWorld extends JFrame { … public CannonWorld () { … getContentPane().add(“East”, scrollbar); } … }

Different Paint Protocol Swing requires you to invoke the parent class paint method from inside an overridden paint method. public class BallWorld extends JFrame { … public void paint (Graphics g) { super.paint(g); // first call parent, then do aBall.paint(g); // class-specific painting } … } Demo (subdir. Swing_Event-drivenCannonWorld)

Different Paint Protocol: Part 2 But, wait!!! Swing JFrame’s should not be directly drawn on. Instead, draw the graphics in a JPanel and embed it in the JFrame. Demo with Panel (almost correct) (subdir. SwingPanel_Event-drivenCannonWorld)