Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
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.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Chapter 5 Ch 1 – Introduction to Computers and Java Defining Classes and Methods 1.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of 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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
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.
Chapter 71 Inheritance Chapter 7. 2 Reminders Project 4 was due last night Project 5 released: due Oct 10:30 pm Project 2 regrades due by midnight.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
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.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
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.
Chapter 5 - Making Music: An On-Screen Piano
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets Java API.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
JAPPLET.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
10/5: Primitives, the for loop Primitive data types –why we mention them Return to counter-controlled repetition.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
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,
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.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Applets Yong Choi School of Business CSU, Bakersfield.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Chapter 8 (Horstmann’s Book) Frameworks Hwajung Lee.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
Chapter 8 Frameworks. Frameworks Framework is a set of cooperating classes and interface types that structures the essential mechanisms of a particular.
10/4: the for loop & the switch structure Primitive data types –why we mention them Return to counter-controlled repetition.
Creating a Java Application and Applet
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
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.
Java Applets Getting Started. Import Files In order to run the applet properly, we have to import some files into our class. These files are: –import.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Java Applets.
A First Look at GUI Applications
Lecture 09 Applets.
Introduction to Java Applets
Java Applets.
Java Applets.
Java Applets.
Java Applets.
Presentation transcript:

Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

OO Concepts Reviewed  Programs consist of communicating objects.  Objects consist of:  fields/data (values or attributes) = properties.  methods= behaviors.  Instantiation = process of creating an object.

More OOP Concepts  Abstract data type (ADT)  Encapsulation  Polymorphism

Java features  Portable  Multithreaded  Secure

Java Graphics/speed ■ JAVA has very good graphics ■ Applets provide access to Graphical User Interface (GUI) ■ JAVA is fast ■ Better Support in recent years

JAVA Development Environment Eclipse 3.2  Review tutorial-March 1  Use for applet development

Each JAVA Applet extends or inherits the JApplet class Methods in JApplet class do nothing unless overriden: init : called automatically when applet is run start: automatically called after init paint: called once after init, when a panel changes, and also after repaint () method is called stop: called when execution is finished destroy:cleans up after applet removed from memory

Business KMartMacys ServiceBusiness Kinkos RetailBusiness The child inherits characteristics of the parent: (both methods and data) Note: Single inheritance in JAVA is-a

An Applet Sample Structure import javax.swing.*; //programs are derived // from javax.swing import java.awt.*; //abstract windows toolkit public class extends JApplet { public void init () { } public void paint (Graphics g) { }

Lab: Applet I CREATE A PROJECT in Eclipse ( Tutorial (if review is necessary) Tutorial I. File/New/Project/Java/JavaPr oject/Next/Finish Project Name: FirstApplet, in the appropriate space.

Lab: Applet I CREATE A Package in the project I. File/New/Package II. Enter a Package Name: fi rstapplet, in the appropriate space III. Finish

Lab: Applet I Create a class within the package Caution: Do not check any buttons on bottom of the screen Right Click on the package name Create a class Enter the Name: of the class – call it FirstApplet Finish

Lab: Applet I package firstapplet; public class FirstApplet { } Extend the class so that it will inherit methods from JApplet public class FirstApplet extends JApplet Add two import statements after the package statement: import javax.swing.JApplet; import java.awt.*; Your screen!

package firstapplet; import java.swing.JApplet; Import java.awt.*; public class FirstApplet extends JApplet { } You will see something similar to this!

package firstapplet; import java.awt.*; Import javax.swing.JApplet; public class FirstApplet extends JApplet { public void init () { } public void paint (Graphics g) { } Add the following within the class!

Save your program 1.Right Click on FirstApplet Project 2.Build project 3.Run 4.Run As 5.Java Applet

Applet Demo Explanation

Add some code! (use your own string values and color) package firstapplet; import java.awt.*; Import javax.swing.JApplet; public class FirstApplet extends JApplet { public void init () { } public void paint (Graphics g) { super.paint (g); Graphics2D g2 = (Graphics2D)g g2.setColor (Color.blue); g2.drawString (“Gayle J Yaverbaum”, 20, 10); g2.drawString (“Penn State Harrisburg”, 20,25); } Caution: DO NOT cut and paste from Powerpoint

Applet Demo Explanation 1. init : is called automatically when applet is run 2.paint: is called once after init and when a repaint method is called. a.super.paint (g) calls the super class inherited from JApplet. Omitting it can cause some subtle drawing errors. b.paint receives the Graphics class as a parameter.

The form is (type) public void draw (Graphics g) { Graphics2D g2=(Graphics2D)g; } Casting: to convert the object "g" to "g2"

 A Graphics object is passed as a parameter to paint ()  setColor is a method in the Graphics class  black (default), blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, and yellow  drawString is a method in Graphics  Parameters are: string, x coordinate, y coordinate

Reminders!  FirstApplet is name of class and must be same as the class name  By convention - class names begin with a capital letter  By convention - package names are the same name as the project name and all lower case  By convention method names begin with a lower-case letter

xml file for FirstApplet Of note!

XSLT

DTD: Element with attributes <!ATTLIST app class CDATA "none" class CDATA "none" width CDATA "none" width CDATA "none" height CDATA "none" height CDATA "none"> <!ATTLIST elementname attributename type default CDATA means character string

Reviews Text: Chapter 7 Reviews A Team Home Page A member Home Page One Applet Page 2..4 sub pages

Extending the Application  DrawClass  Create another class, DrawClass, in your project package  Use the same package name, firstapplet, as before  Create a method, draw, in the class  Draw receives the Graphics class from the calling method

public class DrawClass { public void draw (Graphics g) { }

public class FirstApplet extends JApplet { DrawClass d; public void init () { d = new DrawClass (); } public void paint (Graphics g) { super.paint(g); Graphics2D g2=(Graphics2D)g; g2.setColor (Color.blue); g2.drawString ("Gayle J Yaverbaum", 50, 20); g2.drawString ("Penn State Harrisburg", 50,30); d.draw(g); }

public void draw (Graphics g) { super.paint(g); Graphics2D g2=(Graphics2D)g; g2.setPaint (Color.red); g2.setStroke( (new BasicStroke (10.0f))); g2.draw (new Rectangle2D.Double(100, 50, 100,50)); } Sun Java Tutorial on 2D Graphics Draw Method Ideas