INFSY 547: WEB-Based Technologies
-
Upload
nina-schwartz -
Category
Documents
-
view
24 -
download
1
description
Transcript of INFSY 547: WEB-Based Technologies
![Page 1: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/1.jpg)
Gayle J Yaverbaum, PhDProfessor of Information SystemsPenn State Harrisburg
![Page 2: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/2.jpg)
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.
![Page 3: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/3.jpg)
More OOP Concepts
Abstract data type (ADT)
Encapsulation
Polymorphism
![Page 4: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/4.jpg)
Java features
Portable Multithreade
d Secure
![Page 5: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/5.jpg)
Java Graphics/speed
■ JAVA has very good graphics
■ Applets provide access to Graphical User Interface (GUI)
■ JAVA is fast
■ Better Support in recent years
![Page 6: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/6.jpg)
JAVA Development Environment
Eclipse 3.2 Review tutorial-March 1 Use for applet
development
![Page 7: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/7.jpg)
Each JAVA Applet extends or inherits the JApplet class
Methods in JApplet class do nothing unless overriden:
init : called automatically when applet is runstart: automatically called after initpaint: called once after init, when a panel changes, and also after repaint () method is calledstop: called when execution is finisheddestroy:cleans up after applet removed from memory
![Page 8: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/8.jpg)
![Page 9: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/9.jpg)
Business
KMart Macys
ServiceBusiness
Kinkos
RetailBusiness
The child inherits characteristics of the parent: (both methods and data)
Note: Single inheritance in JAVA
is-a
![Page 10: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/10.jpg)
An Applet Sample Structure
import javax.swing.*; //programs are derived // from javax.swingimport java.awt.*; //abstract windows toolkitpublic class <name of your applet> extends JApplet{ public void init () { }
public void paint (Graphics g) {
}}
![Page 11: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/11.jpg)
Lab: Applet I
CREATE A PROJECT in Eclipse (Tutorial (if review is necessary)
I. File/New/Project/Java/JavaProject/Next/Finish
Project Name: FirstApplet, in the appropriate space.
![Page 12: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/12.jpg)
Lab: Applet I
CREATE A Package in the project
I. File/New/Package
II. Enter a Package Name: firstapplet, in the appropriate space
III. Finish
![Page 13: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/13.jpg)
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
![Page 14: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/14.jpg)
Lab: Applet Ipackage 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!
![Page 15: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/15.jpg)
package firstapplet;import java.swing.JApplet; Import java.awt.*;public class FirstApplet extends JApplet{
}
You will see something similar to this!
![Page 16: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/16.jpg)
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!
![Page 17: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/17.jpg)
Save your program1.Right Click on FirstApplet
Project 2.Build project3.Run4.Run As 5.Java Applet
![Page 18: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/18.jpg)
Applet Demo Explanation
![Page 19: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/19.jpg)
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
![Page 20: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/20.jpg)
Applet Demo Explanation
1. init : is called automatically when applet is run2. 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.
![Page 21: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/21.jpg)
The form is (type)<object or variable>
public void draw (Graphics g){
Graphics2D g2=(Graphics2D)g;
}
Casting: to convert the object "g" to "g2"
![Page 22: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/22.jpg)
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
![Page 23: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/23.jpg)
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
![Page 24: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/24.jpg)
xml file for FirstApplet
<?xml version="1.0"?><!DOCTYPE jclass SYSTEM "jclass.dtd"><jclass> <app class="firstapplet.FirstApplet" width="300" height="250"> </app></jclass>
Of note!
![Page 25: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/25.jpg)
<xsl:template match=“jclass”> <xsl:for-each select="app">
<applet> <xsl:attribute name="code"> <xsl:value-of select="@class"/> </xsl:attribute> <xsl:attribute name="width"> <xsl:value-of select="@width"/> </xsl:attribute> <xsl:attribute name="height"> <xsl:value-of select="@height"/> </xsl:attribute></applet>
<br/><br/><br/> </xsl:for-each></xsl template>
XSLT
![Page 26: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/26.jpg)
DTD: Element with attributes
<!ELEMENT jclass (app+)><!ELEMENT jclass (app+)><!ATTLIST app <!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
![Page 27: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/27.jpg)
Reviews
•Text: Chapter 7•Reviews
• A Team Home Page• A member Home Page• One Applet Page• 2..4 sub pages
![Page 28: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/28.jpg)
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
![Page 29: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/29.jpg)
public class DrawClass{
public void draw (Graphics g){
}}
![Page 30: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/30.jpg)
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); } }
![Page 31: INFSY 547: WEB-Based Technologies](https://reader035.fdocuments.net/reader035/viewer/2022062407/56812d1f550346895d921ba5/html5/thumbnails/31.jpg)
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