1 Lesson: Applets with User Input and Output with GUI ICS4M.

Slides:



Advertisements
Similar presentations
GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
Advertisements

Standard Components and Their Events GUI interface elements are represented by subclasses of component: –Button class –Label class –TextField class –Checkbox.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 9, 2004 Last update:
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
Chapter 5: Keyboard I/O & Simple GUI’s Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
1 Name & Gender Example At a certain University the registry require a small application to help those on the front desk work out the gender with the name.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
CS 178: Programming with Multimedia Objects Aditya P. Mathur Professor of Computer Sciences Purdue University, West Lafayette Sept 20, 2004 Last update:
Programming Task: Task 1 Controlled Assessment Practice.
Io package as Java’s basic I/O system continue’d.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
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.
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.
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’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
String Manipulation. Java String class  The String class represents character strings “Tammy Bailey”  All strings (arrays of characters) in Java programs.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Layout Managers Arranges and lays out the GUI components on a container.
CS100A, Lecture 16, 27 October CS100A Lecture October 1998 Assignment 7: A Checker-playing program: learning about GUIs and working with a.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
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.
For (int i = 1; i
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Java Applet Basics (2). The Body Mass Index Calculator.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
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.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
Creating a GUI Class An example of class design using inheritance and interfaces.
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.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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,
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
Event Handling CS 21a: Introduction to Computing I First Semester,
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
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.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
GUIs & Event-Driven Programming Chapter 11 Review.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
CompSci 230 S Programming Techniques
A First Look at GUI Applications Radio Buttons and Check Boxes
“Form Ever Follows Function” Louis Henri Sullivan
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Predefined Dialog Boxes
AWT Components and Containers
Chapter 5 Processing Input with Applets
CiS 260: App Dev I Chapter 6: GUI and OOD.
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
A picture's worth a thousand words
Presentation transcript:

1 Lesson: Applets with User Input and Output with GUI ICS4M

2 Learning objectives  How to create Label?  How to create TextField?  How to create Button?  How to respond to user action?

3 Applet as a Container Applet Viewer:

4 The “init” method Q: What is init method used for?Q: What is init method used for? A:A: To initialize any instance variables.To initialize any instance variables. To set up the GUI components used by the Applet.To set up the GUI components used by the Applet. public void init ( ) { // Place the body of the init method here. }

5 Demo: BusFare3

6 Label  What is a label? A label is Java’s way of adding a single line of text into an applet. The text is non-interactive. That is, it cannot be clicked on. A label is Java’s way of adding a single line of text into an applet. The text is non-interactive. That is, it cannot be clicked on.

7 How to create a label?  Use constructor: Label myLabel = new Label(“Hello World”); Label myLabel = new Label(“Hello World”); “Hello World” myLabel Note: you need to add this label into the Applet container.

8 TextField  What is a Text field? A Text Field is a single line text input. A Text Field is a single line text input.  Applet’s way of getting input from user.  Q: Where does this class come from?

9 How to create text field?  2 different constructors.  Constructor 1: TextField(int cols) TextField(int cols) Creates a TextField cols columns wide. Creates a TextField cols columns wide.  Constructor 2: TextField (String str, int cols) TextField (String str, int cols) Allows user to initialize the text field with initial string. Allows user to initialize the text field with initial string.

10 Example: Text Field  TextField input;  input = new TextField(5);  Or  TextField input = new TextField(5)

11 Add method  void add (Component comp) Adds Component comp to the Applet using the Applet’s layout manager. Adds Component comp to the Applet using the Applet’s layout manager.  Q: Which class does “add” method belong to?  Q: Why are we using this version of “add” method?

12 Example: add method // Set up GUI components. public void init ( ) { prompt = new Label(“Enter age then press Return”); input = new TextField(5); // Place label and text field on applet add (prompt); add (input); } // init method

13 Action method  boolean action (Event evt, Object o) Call by the system when a button is clicked or an ENTER is pressed in a text field in the applet. Call by the system when a button is clicked or an ENTER is pressed in a text field in the applet. The Button or TextField object that was clicked or had Return pressed is passed as the target field in evt. The Button or TextField object that was clicked or had Return pressed is passed as the target field in evt. The method must return “TRUE” if the event was handled and “FALSE” if the event was not handled. The method must return “TRUE” if the event was handled and “FALSE” if the event was not handled.  Q1: How do we get the input from the TextField?  Q2: How do we put something in a TextField?

14 Demo: BlockButton

15 Buttons  There are 2 constructors for creating buttons: public Button();No Label public Button();No Label public Button(String label)With label public Button(String label)With label  To create a button, we use Button myButton = new Button(“ButtonName”); Button myButton = new Button(“ButtonName”); Then add the button to the container. Then add the button to the container.

16 Class Exercise: Pig Latin  Learn how to use TextArea.  Write the Pig Latin program using Labels, TextField, and TextArea  Hint: Use subString or charAt methods to break up your string into small tokens.  Pig Latin rule: Move the first character of each word to the back and add “ay”. Move the first character of each word to the back and add “ay”. For example: nice  icenay For example: nice  icenay