Java Applet Basics (2). The Body Mass Index Calculator.

Slides:



Advertisements
Similar presentations
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
Advertisements

Standard Components and Their Events GUI interface elements are represented by subclasses of component: –Button class –Label class –TextField class –Checkbox.
Applets The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
Events CSC 171 FALL 2001 LECTURE 9. History: the ABC John Vincent Atanasoff, with John Berry, developed the machine we now call the ABC -- the.
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.
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
COMP 14 Introduction to Programming Miguel A. Otaduy June 8, 2004.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 21, 2005.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Programming Task: Task 1 Controlled Assessment Practice.
Io package as Java’s basic I/O system continue’d.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Button 元件. public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
GUI programming Graphical user interface-based programming.
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.
Copyright © Curt Hill First Windows Program GUIs in Eclipse.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
1 Lesson: Applets with User Input and Output with GUI ICS4M.
Layout Managers Arranges and lays out the GUI components on a container.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative.
2/5/00SEM107 © Kamin & Reddy Review -1 Class 19 - Review r This lecture contains a selection of slides from previous lectures, giving the “high points”
1 Class 6. 2 Objectives Objectives Identify, declare, and use primitive data types Use the System class to create data streams Use the Scanner class of.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
PHY281 Scientific Java Programming ArraysSlide 1 Arrays In this section we will learn how about storing groups of related variables that share the same.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Today’s topics Java Input More Syntax Upcoming Decision Trees More formal treatment of grammers Reading Great Ideas, Chapter 2.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
Graphical User Interface (GUI)
Event Handling CS 21a: Introduction to Computing I First Semester,
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
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.
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
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.
AGENDA FOR APRIL Calculator Phase 3 PowerPoint Presentation 2. Work on Calculator Project Phase 3 Do your best to exceed the expectations of this.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
Design Applet based java program to find the area and perimeter of a rectangle given its length and width. Java GUI.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CompSci 230 S Programming Techniques
Java Applet What is a Java Applet? How is applet compiled?
Ellen Walker Hiram College
Event Handling CS 21a: Introduction to Computing I
CSE Software Engineering Fall 1999 Updated by J. Brown
Graphical user interface-based programming
Chapter 5 Processing Input with Applets
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

Java Applet Basics (2)

The Body Mass Index Calculator

The Applet Skeleton import java.applet.*; import java.awt.*; public class BodyMassApplet extends Applet { }

The HTML Page

Create the Skeleton Files

Control Components Label TextField Button

Add a Label Control import java.applet.*; import java.awt.*; public class BodyMassApplet extends Applet { Label myLabel = new Label(“XXXXXXXX”); public void init() { add(myLabel); }

Member Variable

Add Labels into the Skeleton

Add a TextField Control import java.applet.*; import java.awt.*; public class BodyMassApplet extends Applet { TextField myTextField = new TextField(columns); public void init() { add(myTextField); }

Add TextFields into the Skeleton

Add a Button Control import java.applet.*; import java.awt.*; public class BodyMassApplet extends Applet { Button myButton = new Button(“Text on the Button”); public void init() { add(myButton); }

Add Buttons into the Skeleton

Handle Action Events import java.awt.event.*; public class BodyMassApplet extends Applet implements ActionListener { Button myButton = new Button(“my button”); public void init() { add(myButton); myButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { //handle the event here }

Add the Event Handler

Display Text on a Label Control Syntax: myLabel.setText(“the text shown on the label control”);

Read Text from a TextField Syntax: myTextField.getText(); E.g. String input; input = myTextField.getText();

Read Inputs From all TextFields

Math.round(dbl) Rounds a real number into the nearest integer Syntax: integer = Math.round(dbl) Example: double dblIndex; int intIndex; intIndex = Math.round(dblIndex); Question: what’s the difference between Math.round(dbl) and (int)dbl?

Round the Body Index