May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS 102-01 Lecture 7-3 A picture's worth a thousand words.

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

Programming in Java; Instructor:John Punin Graphics and Graphical User Interfaces1 Programming in Java Graphics and Graphical User Interfaces.
Android User Interface
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
Standard Components and Their Events GUI interface elements are represented by subclasses of component: –Button class –Label class –TextField class –Checkbox.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Components. Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent –TextArea –TextField.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
1 lecture 12Lecture 13 Event Handling (cont.) Overview  Handling Window Events.  Event Adapters Revisited.  Introduction to Components and Containers.
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.
12-Jul-15 Components. 2 Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent TextArea TextField.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
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, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
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,
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Csc Basic Graphical User Interface (GUI) Components.
AWT Package. Java GUI classes are contained in the java.awt package. Java GUI classes are contained in the java.awt package. A graphical Java program.
Review_6 AWT, Swing, ActionListener, and Graphics.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
Graphical User Interfaces (GUI). PART ONE About GUI’s.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
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.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Lecture 09 Applets.
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
AWT Components and Containers
GUI building with the AWT
Constructors, GUI’s(Using Swing) and ActionListner
Programming Graphical User Interface (GUI)
GUI building with the AWT
A picture's worth a thousand words
Graphical User Interface
Presentation transcript:

May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words

May 12, 1998CS102-01Lecture 7-3 Agenda User interface design GUIs in Java Labels Buttons Text

May 12, 1998CS102-01Lecture 7-3 Building UIs Part art, part science –Users: appealing,intuitive and easy-to-use –Developers: Easy to build, easy to maintain and easy to build on

May 12, 1998CS102-01Lecture 7-3 Components Can Barely Contain Themselves Components are the building blocks of GUIs (aka widgets or UI widgets) Components can’t just be left lying around –Containers are objects which can hold components –A Container is-a Component which is-a Object

May 12, 1998CS102-01Lecture 7-3 Components in a Nutshell Details on Component –public abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable –super class of: Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, TextComponent

May 12, 1998CS102-01Lecture 7-3 Components Capture A Lot Track event listeners Peer communication Popup menus Layout features –Sizing –Placement Check out the Component class documentation

May 12, 1998CS102-01Lecture 7-3 Contain Yourself Containers hold Components public abstract class Container extends Component Component Super class of: Panel, ScrollPane, WindowPanelScrollPane Window Remember: An Applet’s a Panel

May 12, 1998CS102-01Lecture 7-3 Add It Up Components are added to Containers –Components added to a container are tracked in a list –Order of the list will define the components' front-to-back stacking order (aka Z-order) within the container

May 12, 1998CS102-01Lecture 7-3 Adding Components add public Component add(Component comp)Component Adds the specified component to the end of this container. Label buttonLabel = new Label(“Nice Button”); Button pressMe = new Button(“Click here!”); // Add the components to a container add(buttonLabel); add(pressMe);

May 12, 1998CS102-01Lecture 7-3 Labeling Labels make it easy to put read-only text on the screen –Just one line of text Better than drawString() –No pixel values to calculate –Choose alignment (LEFT, CENTER, RIGHT) –Set fonts for each label –Reusable

May 12, 1998CS102-01Lecture 7-3 Building Labels Label() –Constructs an empty label. Label(String) –Constructs a new label with the specified string of text, left justified. Label(String, int) –Constructs a new label that presents the specified string of text with the specified alignment.

May 12, 1998CS102-01Lecture 7-3 Handy Label Methods getAlignment() Gets the current alignment of this label. getText() Gets the text of this label. paramString() Returns the parameter string representing the state of this label. setAlignment(int) Sets the alignment for this label to the specified alignment. setText(String) Sets the text for this label to the specified text.

May 12, 1998CS102-01Lecture 7-3 Read-Only for Whom? Users can’t edit text, but you can setText() lets you change the text within your program

May 12, 1998CS102-01Lecture 7-3 Don’t Forget to Add The pattern is: –Build a component buttonLabel = new Label(“Nice Button”); –Add it to the container add(buttonLabel); –Paint the container and components (usually automatic) Someone calls paint()

May 12, 1998CS102-01Lecture 7-3 Bad Adding Build a component, but don’t add it –Never appears Add a component to a non-existent container –Not a problem for us, because we add to the Applet we’re building Adding a not-yet-constructed Component to a Container is bad

May 12, 1998CS102-01Lecture 7-3 Button Up! Push buttons are handy for clicking –Similar to Submit buttons in HTML forms Button is two things: –A label (“Click here”, “Erase disk”) –An event generator Use event handling to tie buttons to “the rest of the program”

May 12, 1998CS102-01Lecture 7-3 Button Housekeeping Java takes care of drawing the button as the user clicks on it

May 12, 1998CS102-01Lecture 7-3 public class MyButtons extends Applet { private Button pushButton1, pushButton2; public void init() { // create buttons pushButton1 = new Button( "Button 1" ); pushButton1.addActionListener( new Button1Handler( this ) ); add( pushButton1 ); pushButton2 = new Button( "Button 2" ); pushButton2.addActionListener( new Button2Handler( this ) ); add( pushButton2 ); } Button Events

May 12, 1998CS102-01Lecture 7-3 Handling Button1 class Button1Handler implements ActionListener { Applet applet; public Button1Handler( Applet a ) { applet = a; } public void actionPerformed( ActionEvent e ) { applet.showStatus( "You pressed: " + e.getActionCommand() ); }

May 12, 1998CS102-01Lecture 7-3 Handling Button2 class Button2Handler implements ActionListener { Applet applet; public Button2Handler( Applet a ) { applet = a; } public void actionPerformed( ActionEvent e ) { applet.showStatus( "You pressed: " + e.paramString() ); }

May 12, 1998CS102-01Lecture 7-3 TextFields Display text –Users can edit, if you let them Use setEditable(boolean) to decide whether users can edit –Still just one line A TextField is-a TextComponent, which is-a ___________

May 12, 1998CS102-01Lecture 7-3 A Few Good Methods Echo characters –echoCharIsSet() –getEchoChar() –setEchoChar(char) Columns –setColumns(int) –getColumns() Rows?