CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.

Slides:



Advertisements
Similar presentations
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
Advertisements

1 Review of applets & Computer Graphis GUILecture 6 Review of Applets & Compute Graphics GUI Overview  Introduction to Graphics. Applets: a quick review.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
©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.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
JAVA APPLETS By: Ms. Humaira Siddiqui. Java and the Internet Java is considered to be a language well suited to be used in the internet. In contrast with.
© 2007 Lawrenceville Press Slide 1 Chapter 2 HTML An example HTML document Hello world!
Java applet basics, loading & displaying images After this section, you should be able to : –Use the applet tag and applet parameters –Describe what a.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original (non-OOP)
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
9/21/99www.cs.vt.edu/wwtut/1 User Interface Programming In Java Part 1 – Introduction Marc Abrams Virginia Tech CS Dept courses.cs.vt.edu/wwwtut/
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 9.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
User-defined parameters can be passed to an applet using the tags.
Exposure Java-A 2006 Chapter 4 Slides Using Methods and Parameters
Applets Session 8. Java Simplified / Session 8 / 2 of 31 Review The Abstract Windowing Toolkit (AWT) is a set of classes that allow us to create a graphical.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Applet in Java Abhishek Singh. Advantage of Applet There are many advantages of applet. They are as follows : It works at client side so less response.
CPS Today’s topics Java Applications Graphics Upcoming Review for Midterm Exam Reading Great Ideas, Chapters 5.
1 Windows program example import java.awt.*; import java.awt.event.*; public class wpexample extends Frame { public wpexample(String title) { super(title);
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
25/2/00SEM107 - © Kamin & ReddyClass 9 - HTML - 1 Class 9 - HTML r Creating a personal web page r Structure of HTML documents r HTML tags r The APPLET.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.
1 Contents Introduction Applet Vs Application Security Restrictions on Applet A simple example “Hello World!” applet Compiling & Running Applet HTML document.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class.
1 CSC 551: Web Programming Spring 2004 Java Applets  Java vs. C++  instance vs. class variables, primitive vs. reference types, inheritance  graphical.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Chapter 14 Applets and More. 2 Contents I. Introduction to Applets II. A Brief Introduction to HTML III. Creating Applets with Swing IV. Using AWT for.
Graphics Applets By Mr. Dave Clausen
User Interface Programming In Java
Chapter 8 Graphics.
Object Oriented Programming
Java Applet.
Applets In Java Visit for more Learning Resources 1.
Graphics Applets By Mr. Dave Clausen
Today’s topics Java Applications Upcoming Reading Graphics
Chapter 10 Graphics.
Java Applets.
עקרונות תכנות מונחה עצמים
APPLET.
Chapter 8 Graphics.
Applet in Java.
Chapter 13 Graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Chapter 13 Graphics.
Presentation transcript:

CSI 3125, Preliminaries, page 1 Applet

CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is used to draw the specified string. public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height. public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height. public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height. public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.

CSI 3125, Preliminaries, page 3 Graphics Methods public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2). public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image. public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc. public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or elliptical arc. public abstract void setColor(Color c): is used to set the graphics current color to the specified color. public abstract void setFont(Font font): is used to set the graphics current font to the specified font.

CSI 3125, Preliminaries, page 4 Applet Example import java.applet.Applet; import java.awt.*; public class GraphicsDemo extends Applet{ public void paint(Graphics g){ g.setColor(Color.red); g.drawString("Welcome",50, 50); g.drawLine(20,30,20,300); g.drawRect(70,100,30,30); g.fillRect(170,100,30,30); g.drawOval(70,200,30,30); g.setColor(Color.pink); g.fillOval(170,200,30,30); g.drawArc(90,150,30,30,30,270); g.fillArc(270,150,30,30,0,180); }

CSI 3125, Preliminaries, page 5 Image in Applet Displaying Image in Applet The java.awt.Graphics class provide a method drawImage() to display the image. Syntax of drawImage() method: public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.

CSI 3125, Preliminaries, page 6 Image in Applet import java.awt.*; import java.applet.*; public class DisplayImage extends Applet { Image picture; public void init() { picture = getImage(getDocumentBase(),“popo.jpg"); } public void paint(Graphics g) { g.drawImage(picture, 30,30, this); } The 4th argument of drawImage() method of is ImageObserver object. Current class object would also be treated as ImageObserver because Applet class indirectly extends the Component class.

CSI 3125, Preliminaries, page 7 Passing Parameters to Applets Parameters are passed to applets in NAME=VALUE pairs in tags between the opening and closing APPLET tags. Inside the applet, the values can be read using the getParameter() method of the java.applet.Applet class.

CSI 3125, Preliminaries, page 8 Passing Parameters to Applets import java.applet.*; import java.awt.*; /* */ public class para1 extends Applet { String s; public void init() { s=getParameter("first"); } public void paint(Graphics g) { g.drawString("Parameter is "+s,100,100); }

CSI 3125, Preliminaries, page 9 Passing Parameters to Applets import java.applet.*; import java.awt.*; /* */ public class para2 extends Applet { int x,y,sum; public void init() { x=Integer.parseInt(getParameter("first")); y=Integer.parseInt(getParameter("second")); } public void paint(Graphics g) { sum=x+y; g.drawString("Total Sum is "+sum,100,100); }

CSI 3125, Preliminaries, page 10 Adding sound to an applet. There are really only two steps required to play a sound in a Java applet: (1) loading the sound file into an AudioClip object, and (2) playing the sound using the play() method of the AudioClip class.

CSI 3125, Preliminaries, page 11 Adding sound to an applet. import java.applet.*; public class Sound extends Applet { public void init() { AudioClip g = getAudioClip(getDocumentBase(), "a.au"); g.play(); } /* */

CSI 3125, Preliminaries, page 12 Applet sound control with Button import java.applet.*; import java.awt.*; import java.awt.event.*; /* */ public class PlaySoundApplet extends Applet implements ActionListener{ Button play,stop; AudioClip audioClip; public void init(){ play = new Button("Play"); add(play); play.addActionListener(this); stop = new Button("Stop"); add(stop); stop.addActionListener(this); audioClip = getAudioClip(getCodeBase(), "a.au"); } public void actionPerformed(ActionEvent ae){ Button source = (Button)ae.getSource(); if (source.getLabel() == "Play"){ audioClip.play(); } else if(source.getLabel() == "Stop"){ audioClip.stop(); }

CSI 3125, Preliminaries, page 13 Applet