Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.

Slides:



Advertisements
Similar presentations
Made with love, by Zachary Langley Applets The Graphics Presentation.
Advertisements

Lecture 2 Internet Computing Using Java Theophano Mitsa UMASS-Dartmouth.
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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
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.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
 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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
1 L44 Introduction to Java Applets. 2 OBJECTIVES  To differentiate between applets and applications.  To observe some of Java's exciting capabilities.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
 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.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Applets.
JAPPLET.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
1 Applets and Course Evaluation Applet Example - Sailing Applet UML Diagrams Applet Web Page Encoding (HTML) Applet Java Coding – Hello World Course Evaluation.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
习 题 4.23 编写一个 applet ,读取一个矩形的边长,然后 用在 paint 方法中使用 drawString 方法画出用星组成 的空心矩形。程序应能画出边长从 1 到 20 的任何矩 形。
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
2/4: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance Java Applets –what is an applet vs. an application? –where do applets.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.3Sample.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Java applets. Outline What is Java? Java Applications Java Applets Java Applets Securities Summary.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Copyright © Curt Hill Applets A different type of program.
CSC 243 – Java Programming, Spring, 2014 April 22, 2014 Week 13, JApplets.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
2/4: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance –information hiding –classes: blueprints for objects Java Applets.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Lecture 09 Applets.
Java Applets.
Object Oriented Programming (OOP) LAB # 5
Applets.
Java Applets.
Java Applets.
Java applets 1/3/2019.
Applet in Java.
Java Programming COMP-417 Applet
Applet 2019/4/23.
Outline Character Strings Variables and Assignment
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
APPLET PROGRAMMING.
Presentation transcript:

Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal

Introduction to java applet

Applet  Program that runs in  appletviewer (test utility for applets)  Web browser (IE, Communicator)  A main() method is not invoked on an applet, and an applet class will not define main().  Applets are designed to be embedded within an HTML page.  When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine.

Applet viewer Running applet in web browser

Life Cycle of an Applet: There are four methods when using applet: init : This method is intended for whatever initialization is needed for an applet. start : This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages. stop : This method is automatically called whenever the user moves away from the page containing applets. This method can be used to stop an animation. destroy : This method is only called when the browser shuts down normally.

Life Cycle of an Applet:  browser visits page containing an applet  browser calls init on that applet, once  browser calls start on that applet  browser goes away from that page  browser calls stop on that applet  browser comes back to that page  browser calls start again on that applet  browser shuts down  browser calls destroy on the applet, once

Is it necessary to use all applet’s methods ?

Exercise #1  Write an applet that allows the user to input values for the arguments required by method drawRect, then draws a rectangle using the four input values.

import allows us to use predefined classes (allowing us to use applets and graphics, Scanner in this case). To use JApplet, you have to import javax.swing.JApplet To paint or draw a rectangle or any thing else, you must import java.awt.Graphics To ask user to insert numbers, you must import java.util.Scanner. extends allows us to inherit the capabilities of class JApplet. Define the variables we need. Why aren’t they written inside init function? Ask user to insert each variable in (init) function. Define paint method to draw a rectangle. drawRect takes 4 parameters. The two start points, the width and the height of the rectangle.

Testing#1

Exercise #2  Write an applet that reads five integers and determines and prints the largest and smallest integers in the group. Draw the results on the applet. Use JOptionPane to insert each values of the five integers.

import allows us to use predefined classes (allowing us to use applets and graphics, JOptionPane in this case). To use JApplet, you have to import javax.swing.JApplet To paint or draw a String or any thing else, you must import java.awt.Graphics To ask user to insert numbers using JOptionPane, you must import javax.swing.JOptionPane extends allows us to inherit the capabilities of class JApplet. Define the variables we need. Why aren’t they written inside init function? Ask user to insert each variable using JoptionPane. The first string we want to draw. It contains all five numbers. Find the smallest number of the five integers. The second value we want to paint.

Find the largest number of the five integers. The third text we want to draw. Use drawString to draw the three texts we stored before. drawString takes three parameters. The string to be displayed and it’s position.

Testing…..

Exercise #3  Write an applet that calculates the squares and cubes of the numbers from 0 to 10 and draws the resulting values in table format as shown below. [Note: This program does not require any input from the user].

The End !!