Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.

Slides:



Advertisements
Similar presentations
Introduction to Web Design Lecture number:. Todays Aim: Introduction to Web-designing and how its done. Modelling websites in HTML.
Advertisements

Introduction to HTML. A Web Page is.. An ASCII (text) file.. Whose filename ends with.htm or.html –index.html or cookie-recipe.htm Contains HTML tags.
HTML popo.
Internet Services and Web Authoring (CSET 226) Lecture # 5 HyperText Markup Language (HTML) 1.
Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
INTRODUCTION TO HYPERTEXT MARKUP LANGUAGE 1. Outline  Introduction  Markup Languages  Editing HTML  Common Tags  Headers  Text Styling  Linking.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
1 HTML Markup language – coded text is converted into formatted text by a web browser. Big chart on pg. 16—39. Tags usually come in pairs like – data Some.
1 Introduction to Applets Overview l What is an Applet? l Steps for creating an applet l What is HTML? l Basic HTML tags l Drawing Simple Graphical shapes.
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.
1 L44 Introduction to Java Applets. 2 OBJECTIVES  To differentiate between applets and applications.  To observe some of Java's exciting capabilities.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
 2008 Pearson Education, Inc. All rights reserved. 1 Introduction to HTML.
Introduction to Java A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
Creating a Web Page HyperText Markup Language. HTML Documents  Created using any text editor  Notepad  Vi, Pico, or Emacs  If using word-processor,
HTML Lesson 1 TBE 540 Farah Fisher. Prerequisites Before beginning this lesson, the student must be able to… Access web pages and navigate the web Access.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
1 Creating a Web Page An introduction to Hypertext Markup Language (HTML) ~~~~~ ~~~~ ~~~~~
HTML Tags. Objectives Know the commonly used HTML tags Create a simple webpage using the HTML tags that will be discussed.
Presenting Information on WWW using HTML. Presenting Information on the Web with HTML How Web sites are organized and implemented A brief introduction.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
HTML HTML stands for "Hyper Text Mark-up Language“. Technically, HTML is not a programming language, but rather a markup language. Used to create web pages.
Dr. Nuha El-KhaliliInternet Programming ( ) HTML Hyper Text Markup Language The language of web pages Maintained by the W3C
Chapter 4: Hypertext Markup Language Primer TECH Prof. Jeff Cheng.
Understanding HTML Code
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.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module F Building a Web Page with HTML.
1 CSC 121 Computers and Scientific Thinking David Reed Creighton University HTML and Web Pages.
Chapter 4 (through page 110) Fluency with Information Technology 4 th edition by Lawrence Snyder (slides by Deborah Woodall : 1.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Just Enough HTML How to Create Basic HTML Documents.
HTML Hyper Text Markup Language. What is an HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup.
All you ever needed to know…and more!. H.T.M.L. HyperText Mark-up Language Web’s programming language All web browsers Set of instructions Written with.
INTRODUCTION. What is HTML? HTML is a language for describing web pages. HTML stands for Hyper Text Markup Language HTML is not a programming language,
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
CS105 INTRODUCTION TO COMPUTER CONCEPTS HTML Instructor: Cuong (Charlie) Pham.
HTML: Hyptertext Markup Language Doman’s Sections.
CPSC 203 Introduction to Computers Lab 33 By Jie Gao.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
Introduction to HTML Xiangming Mu 9/23/ Learning Objectives Understand basic HTML tags and their attributes Learn to create a simple HTML page.
LEARNING HTML PowerPoint #1 Cyrus Saadat, Webmaster.
HTML Lesson 3 Hyper Text Markup Language. Assignment Part 2  Set the file name as “FirstName2.htm”  Set the title as “FirstName LastName First Web Site”
Chapter 4 Applets Cop Why Applets? WWW makes huge information available to anyone with web browser. Web server send web pages and images to your.
Introduction to Computers 12/6/ BEGINNING HTML DESIGNING YOUR OWN WWW PAGES.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Chapter 27 HTTP and WWW.
CSE 409 – Advanced Internet Technology 1 DISCUSSION OF BASIC HTML TAGS.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
Basic HTML Programming Technology Education Ellsworth Community Middle School Communication Systems.
HTML. INDEX Introduction to HTML Creating Web Pages Commands And Tags Web Page.
1 HTML. 2 Full forms WWW – world Wide Web HTTP – Hyper Text Transfer Protocol HTML – Hyper Text Markup Language.
1 Foundation of HTML Web Page Design. 2 Safe Web Fonts: Used by most computers regardless of environment or platform  Times New Roman  Arial  Courier.
HTML AN INTRODUCTION TO WEB PAGE PROGRAMMING. INTRODUCTION TO HTML With HTML you can create your own Web site. HTML stands for Hyper Text Markup Language.
Revised June 2008 Online PD Basic HTML1 Let’s Try It!  Open Notepad oStart > All Programs > Accessories > Notepad oDon’t get WordPad by mistake – won’t.
HTML Help book. HTML HTML is the programming language used to make web pages for the Internet. HTML stands for Hyper Text Markup Language. HTML is made.
Online PD Basic HTML The Magic Of Web Pages
Lecture 16: Applets & HTML
COMPUTING FUNDAMENTALS
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Chapter 27 WWW and HTTP.
Computers and Scientific Thinking David Reed, Creighton University
Basic HTML and Embed Codes
Java Applets.
Introduction to HTML.
Handout-14 Applets and Graphics
Presentation transcript:

Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia

Java Applets  Introduction to Applets  Applet Development  Graphics

Java Applications and Applets  In Java, you can develop applications and applets  Applications can run by themselves  Applets are executed in a controlled environment, usually within web browsers  Let us see some examples of applets embedded in a web page

Some Applets  Hilo Game:  0/fall2003/Applets/HiLo/Hi.html 0/fall2003/Applets/HiLo/Hi.html  Hangman Game:  dex.html dex.html

Applet Mechanism  Java applets are programs that are stored with a web page  When a user requests that web page, the applet embedded with it is sent from the server to the user’s computer  Then the applet is executed in a “sandbox” preventing it from corrupting the user’s computer

Applet Development  There are two distinct phases in applet development  The first phase is concerned with the development of the actual Java applet  The second phase is about embedding the applet in a web page  Let us try to change the programs developed earlier to applets

Application Source Code  import javax.swing.JOptionPane;  public class myfirst {  public static void main(String[] args) {  String input = JOptionPane.showInputDialog("What is your name?");  JOptionPane.showMessageDialog(null,"Good Morning "+input,"Greeting Window",JOptionPane.ERROR_MESSAGE);  System.exit(0);}  }

Converting to Applet  Add the following line at the top:  import javax.swing.JApplet;  Add “extends JApplet” after the class name  Rename the main( ) to myfirst( ). There is no main( ) method in an applet. Use public myfirst( ) instead of the long list of prequalifiers in the method title

Constructors  This new method “public myfirst( )” bears the name of the class to which it belongs  Such methods are known as constructors. They are very useful for initializing a program  Constructors come in handy when there is no main( ) method in a class

Embedding an applet inside a web page  Web pages are written in a language called HTML (HyperText Markup Language)  HTML provides tags and their attributes for formatting the text  Following table shows the common tags used in web pages

Table 9.1 Common tags Meaning Meaning document document head document body document title different header levels boldface Italic underlined subscript superscript centered line break ordered list unordered list an item in the list an image an address (hyperlink) Beginning Tag Ending Tag

Sample Document This is the photo of a race: Program 9.4 HTML Program

Tags and Attributes  In the HTML file (or the web page) shown on the previous slide, a tag named img is used  The attributes of img are “src” and “align”  The “src” attribute points to the source of the image  The “align” attribute lets us select left, center or middle position for the image  Try to save the HTML file and load it in the web browser. The image file is provided through a separate URL on the course homepage

A Web Page that embeds our applet  <applet  width=780  height=500  code="myfirst.class">  The description seen by inept browsers

Explanation  In this web page, we use a tag named “applet”  The attributes of this tag include the width and height of the applet window and code file name  Remember that the code file name used here is “myfirst.class” instead of “myfirst.java”  This is because we need a compiled and ready to run program as an applet  Please save this web page in a.html file  Compile the applet and then load the.html file to see it run  Demo required

Graphics  We can draw various shapes inside an applet window  A specific method named paint( ) is added to the applet in order to draw shapes  Let us try to draw a rectangle  Java defines a class Rectangle that can be used directly

Using Rectangle Class  Add the following import line at the top  import java.awt.Rectangle;  Define a rectangle in the program as follows:  Rectangle book1 = new Rectangle(20,30,200,120)  The parameters are left top ‘x’ and ‘y’ followed by ‘width’ and ‘height’  In a Java graphics window, x increases left to right and y increases top to bottom

Keeping it Simple  In order to keep it simple and manageable, we replace the constructor method by paint method  Replace the title line –public myfirst( )  By this line –public void paint(Graphics g)

Inside the Paint method  Inside the paint() method, simply add the following line –Graphics2D g2 = (Graphics2D)g;  The above line is required in order to use advanced 2-D graphics features  Next insert the rectangle line as on slide 17  Call the draw method to draw the rectangle –g2.draw(book1);  You may use fill method to fill the box with the current color  Demo required for fill method

Changing Colors  The default fill color is black but we can change the colors !!!  Add the following import line at the top –Import java.awt.Color;  Define a new color with the following line inside the program just before the fill call –Color Fillcolor = new Color(1.0f, 0.2f, 0.3f);  Here the three floating point numbers represent the strengths of red, green and blue in fillcolor  Now set the current color with the following line –g2.setColor(fillcolor);  Demo: run the program, make at least two new colors and run again

Drawing Lines  Add the following line at the top of the program: –import java.awt.geom.Line2D;  Define a new line –Line2D.Double bar = new Line2D.Double(20,200,220,200);  Draw the line with the following statement –g2.draw(bar);  Note how carefully we have placed the line below the shape drawn earlier  Programming Exercise: Draw the front of a colonial home with vaulted ceiling, front entrance door and one window. Fill the door and window with colors as desired