13 April 2010 GUIS: Graphical User Interfaces

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Java Software Development Paradigm Lecture # 12. Basics of GUI.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Corresponds with Chapter 12
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
1 Listening to events on GUIs Sec contains this material. Corresponding lectures on ProgramLive CD is a better way to learn the material. Top finalists.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Review Session for EXCEPTIONS & GUIS -David Gries 1 Adapted from Previous Review Slides.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
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.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
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.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
1 12 Apr 2011 GUIS: Graphical User Interfaces Their mouse had a mean time between failure of … a week … it would jam up irreparably, or... jam up on the.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
1 Lecture 25 Listening to buttons and mice Quotes by Tony Hoare There are two ways of constructing a software design: (1) make it so simple that there.
1 GUIS: Graphical User Interfaces Their mouse had a mean time between failure of … a week … it would jam up irreparably, or... jam up on the table--...
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
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 in 1 Graphical User Interface 3 Nouf Almunyif.
1 CS211 Lecture 24 GUIs (Graphical User Interfaces) Readings in Weiss: Appendix B does a good job of laying out the basics. Study it! ProgramLive has a.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Chapter 7 A First Look at GUI Applications Layout Managers.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Graphical User Interfaces
2110: GUIS: Graphical User Interfaces
Java GUI.
8 April 2008 GUIS —Graphical User Interfaces
Review Session for EXCEPTIONS & GUI -Deepak Bapat
CS2110 Lecture 14. GUIS-Layout Spring 2016
Chapter 13: Advanced GUIs and Graphics
GUIS: Graphical User Interfaces
GUIS: Graphical User Interfaces
Creating Graphical User Interfaces
2110: GUIS: Graphical User Interfaces
GUI building with the AWT
Chapter 7-3 (Book Chapter 14)
2110: GUIS: Graphical User Interfaces
2110: Announcements Grades for Prelim 1 are now available. You should have received an from Gradescope about accessing them. Regrade requests will.
GUI building with the AWT
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

13 April 2010 GUIS: Graphical User Interfaces Read Chap. 17 of the text. ProgramLive CD: a better way to learn about GUIs. See the CD for examples of code. Their mouse had a mean time between failure of … a week … it would jam up irreparably, or ... jam up on the table-- ... It had a flimsy cord whose wires would break. Steve Jobs: "... Xerox says it can't be built for < $400, I want a $10 mouse that will never fail and can be mass produced, because it's going to be the primary interface of the computer ..." ... Dean Hovey ... came back, "I've got some good and some bad news. Good news: we've got a new project with Apple. Bad news: I told Steve we'd design a mouse for 10 bucks." ... year later ... we … filed … and were granted a patent, on the electro-mechanical-optical mouse of today; ... we ended up ... [making] the mouse as invisible to people as it is today. Steve Sachs interview on 1st computer with GUI: Apple Lisa (about $9,999 in 1982). http://library.stanford.edu/mac/primary/interviews/sachs/trans.html

South East West Center North JFrame’s content pane Layout manager: An instance controls the placement of components. JFrame layout manager default: BorderLayout. BorderLayout layout manager: Can place 5 components: Container cp= getContentPane(); JButton jb= new JButton(“Click here”); JLabel jl= new JLabel( “label 2”); cp.add(jb, BorderLayout.EAST); cp.add(jl, BorderLayout.WEST); pack(); setVisible(true); South East West Center North JFrameDemo.java

Putting components in a JFrame import java.awt.*; import javax.swing.*; /** Demonstrate placement of components in a JFrame. Use BorderLayout. It places five components in the five possible areas: (1) a JButton in the east, (2) a JLabel in the west, (3) a JLabel in the south, (4) a JTextField in the north, and (5) a JTextArea in the center. */ public class ComponentExample extends JFrame { /** Constructor: a window with title t and 5 components */ public ComponentExample(String t) { super(t); Container cp= getContentPane(); cp.add(new JButton("click me"), BorderLayout.EAST); cp.add(new JTextField("type here", 22), BorderLayout.NORTH); cp.add(new JCheckBox("I voted today"), BorderLayout.SOUTH); cp.add(new JLabel("label 2"), BorderLayout.WEST); cp.add(new JTextArea("type\nhere", 4, 10), BorderLayout.CENTER); pack(); } ComponentExample.java

What components can go in a JFrame Packages that contain classes that deal with GUIs: java.awt: Old package. javax.swing: New package. Javax.swing has a better way of listening to buttons, text fields, etc. Its components are more flexible. JButton, Button: Clickable button JLabel, Label: Line of text JTextField, TextField: Field into which the user can type: JTextArea, TextArea: Many-row field into which user can type JPanel, Panel: Used for graphics; to contain other components JCheckBox: Checkable box with a title JComboBox: Menu of items, one of which can be checked JRadioButton: Same functionality as JCheckBox Container: Can contain other components Box: Can contain other components Component: Something that can be placed in a GUI window. They are instances of certain classes, e.g.

Basic Components Component Button, Canvas Checkbox, Choice Label, List, Scrollbar TextComponent TextField, TextArea Container JComponent AbstractButton JButton JToggleButton JCheckBox RadioButton JLabel, JList JOptionPane, JPanel JPopupMenu, JScrollBar, JSlider JTextComponent JTextField, JTextArea Component: Something that can be placed in a GUI window. These are the basic ones that one uses in a GUI Note the use of subclasses to provide structure and efficiency. For example, there are two kinds of JToggleButtons, so that class has two subclasses.

Components that can contain other components Box Container JComponent JPanel Panel Applet Window Frame JFrame JWindow java.awt is the old GUI package. javax.swing is the new GUI package. When they wanted to use an old name, they put J in front of it. (e.g. Frame and JFrame) When constructing javax.swing, the attempt was made to rely on the old package as much as possible. So, JFrame is a subclass of Frame. But they couldn’t do this with JPanel.

JPanel as a container import java.awt.*; import javax.swing.*; /** Instance has labels in east /west, JPanel with four buttons in center. */ public class PanelDemo extends JFrame { JPanel p= new JPanel(); /** Constructor: a frame with title "Panel demo", labels in east/west, blank label in south, JPanel of 4 buttons in the center */ public PanelDemo() { super("Panel demo"); p.add(new JButton("0")); p.add(new JButton("1")); p.add(new JButton("2")); p.add(new JButton("3")); Container cp= getContentPane(); cp.add(new JLabel("east"), BorderLayout.EAST); cp.add(new JLabel("west"), BorderLayout.WEST); cp.add(new JLabel(" "), BorderLayout.SOUTH); cp.add(p, BorderLayout.CENTER); pack(); show(); } JPanel as a container JPanel layout manager default: FlowLayout. FlowLayout layout manager: Place any number of components. They appear in the order in which they were added, taking as many rows as necessary.

Class Box: a container import javax.swing.*; import java.awt.*; /** Demo class Box. Comment on constructor says how frame is laid out. */ public class BoxDemo extends JFrame { /** Constructor: frame with title "Box demo", labels in the east/west, blank label in south, horizontal Box with 4 buttons in center. */ public BoxDemo() { super("Box demo"); Box b= new Box(BoxLayout.X_AXIS); b.add(new JButton("0")); b.add(new JButton("1")); b.add(new JButton("2")); b.add(new JButton("3")); Container cp= getContentPane(); cp.add(new JLabel("east"), BorderLayout.EAST); cp.add(new JLabel("west"), BorderLayout.WEST); cp.add(new JLabel(" "), BorderLayout.SOUTH); cp.add(b, BorderLayout.CENTER); pack(); show(); } Class Box: a container Box layout manager default: BoxLayout. BoxLayout layout manager: Place any number of components. They appear in the order in which they were added, taking only one row.

public class BoxDemo2 extends JFrame { /** Constructor: frame with title t and 3 columns with n, n+1, and n+2 buttons. */ public BoxDemo2(String t, int n) { super(t); // Create Box b1 with n buttons. Box b1= new Box(BoxLayout.Y_AXIS); for (int i= 0; i != n; i= i+1) b1.add(new JButton(”1 " + i)); // Create Box b2 with n+1 buttons. Box b2= … // Create Box b3 with n+2 buttons. Box b3= … // Create horizontal box b containing b1, b2, b3 Box b= new Box(BoxLayout.X_AXIS); b.add(b1); b.add(b2); b.add(b3); Container cp= getContentPane(); cp.add(b, BorderLayout.CENTER); pack(); show(); } Boxes within a Box 3 vertical boxes, each a column of buttons, are placed in a horizontal box BoxLayout layout manager: Place any number of components. They appear in the order in which they were added, taking only one row.

Simulate BoxLayout Manager in a JFrame To simulate using a BoxLayout manager for a JFrame, create a Box and place it as the sole component of the JFrame: JFrame jf= new JFrame(“title”); Box b= new Box(BoxLayout.X_AXIS); Add components to b; jf.add(b,BorderLayout.CENTER);

Interested in learning more about GUIS? Start developing a GUI by changing an already existing one. There are a lot of details, and it is hard to get all the details right when one starts from scratch and has little idea about the Java GUI package. The easiest way to learn about GUIs is to listen the ProgramLive lectures in Chapter 17. That chapter shows you code for everything, and you can also download the code from the CD and compile and use it yourself. We have shown you how to place components in a GUI. We haven’t yet shown you how to “listen” to things like button clicks in a GUI. That comes later.