Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.

Slides:



Advertisements
Similar presentations
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Advertisements

Java Applet & JavaScript SNU OOPSLA Lab. October 2005.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
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.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Computer Science 103 Chapter 4 Advanced JavaScript.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Java Programming Chapter 10 Graphical User Interfaces.
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.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
CS413: Java Programming language Applications Applets
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Computer Science and Engineering Department VI I - SEMESTER Subject Name : MIDDLEWARE TECHNOLOGIES LABORATORY Subject Code : IT-404.
Graphics in Java Starring: NetBeans Co-Starring: Java.awt.
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
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.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Topics Introduction Scene Graphs
Java Applet Basics (2). The Body Mass Index Calculator.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
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.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
Creating a Java Application and Applet
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
CSC 205 Programming II Lecture 5 AWT - I.
A First Look at GUI Applications
Lecture 09 Applets.
Chapter Topics 15.1 Graphical User Interfaces
Section 64 – Manipulating Data Using Methods – Java Swing
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Graphical user interface-based programming
UNIT-5.
Java Applets.
Chapter 15: GUI Applications & Event-Driven Programming
Chapter 5 Processing Input with Applets
11.1 Applets & graphics.
Presentation transcript:

Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet

Chapter 3: Manipulating Data Using Methods 2 Chapter Objectives Implement an ActionListener to handle events Add interface components to an applet Use the init() and paint() methods to load the applet interface Use the actionPerformed() method Run and test an interactive applet

Chapter 3: Manipulating Data Using Methods 3 Moving to the Web Create a new Java Applet in NetBeans: –Right click on the bodymasscalculator package and select New > Java > Applet –Name the Applet BodyMassApplet

Chapter 3: Manipulating Data Using Methods 4 Moving to the Web The applet version of the Body Mass Index Calculator has four kinds of objects – Image, Labels, TextFields, and Buttons Import three packages –Java.applet.* –Java.awt.* –Java.awt.event.* Implement an ActionListener interface in the class header –Informs the program to respond to user-driven events

Chapter 3: Manipulating Data Using Methods 5 Moving to the Web

Chapter 3: Manipulating Data Using Methods 6 Moving to the Web Every event class has one or more associated listener interfaces

Chapter 3: Manipulating Data Using Methods 7 Adding Interface Components to an Applet Label –Displays text in the applet window TextField –Displays a text box for users to enter text Buttons –Displays a command button for users to click

Chapter 3: Manipulating Data Using Methods 8 Label and Textfield Declarations Construct the components to be displayed in the applet

Chapter 3: Manipulating Data Using Methods 9 The init() Method Initializes the window color and graphic Adds components to the applet window Registers the Button’s ActionListener

Chapter 3: Manipulating Data Using Methods 10 The actionPerformed() Method When a click event occurs, the ActionListener’s actionPerformed() method is triggered –Input values are retrieved with getText() –Calculations are performed –Output is sent to a label with setText()

Chapter 3: Manipulating Data Using Methods 11 The paint() Method Draws the initialized image in the applet window

Chapter 3: Manipulating Data Using Methods 12 Creating an HTML Host Document for an Interactive Applet Compile the applet NetBeans creates an HTML Host Document to execute the applet –Uses the tag to specify the bytecode file, and width and height of the window (NetBeans uses defaults for width and height) Use the same sample data to test the applet

Chapter 3: Manipulating Data Using Methods 13 Summary Applet code is controlled by first defining Labels, TextFields and Buttons Use the add method to place the items on in the web document Create an actionPerformed method to be executed when a button is clicked

Chapter 3: Manipulating Data Using Methods 14 Rest of Today Complete a Java Applet for the body mass calculator –Full list of the code can be found on page 190 of the book Once built copy the logo.gif file to the “build” folder, edit the HTML file to change the height to 500 and open the HTML file.