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/

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Advertisements

Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Introduction to Java Kiyeol Ryu Java Programming Language.
 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.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
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.
Principles of Object-Oriented Software Development The language Java.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
COMP 519: Web Programming Fall 2006 Acknowledgment: The slides are by Dr. David Reed.Dr. David Reed Java Overview  Design goals & features  platform.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
Applets. What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
1 CSC 551: Web Programming Spring 2004 Java Overview  Design goals & features  platform independence, portable, secure, simple, object-oriented, … 
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
Introduction to Java Programming with JBuilder 4
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
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.
Internet Software Development Applets Paul J Krause.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets.
JAPPLET.
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.
Introduction to Java Programming. History F James Gosling and Sun Microsystems F Oak F Java, May 20, 1995, Sun World F HotJava –The first Java-enabled.
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
POS 406 Java Technology And Beginning Java Code
Introduction to Java Programming with Forte Y. Daniel Liang.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
Java Tutorial Ethan New York University.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
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 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.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Java -- A very Hot Object- Oriented Language Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of.
Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
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.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
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.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Introduction to Java Programming, 4E Y. Daniel Liang.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
User Interface Programming In Java
Chapter No. : 1 Introduction to Java.
Object Oriented Programming
Applets In Java Visit for more Learning Resources 1.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Java applets 1/3/2019.
Applet in Java.
A Brief History January 1996: first official release JDK 1.0
APPLET PROGRAMMING.
Presentation transcript:

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/

9/21/99www.cs.vt.edu/wwtut/2 History Evolved from Sun project to write code for consumer electronics Gosling and colleagues began adding/subtracting C++ features In 1993, developers realized Java’s potential for Web. Wrote HotJava browser, with HTML support for applets.

9/21/99www.cs.vt.edu/wwtut/3 Java 1 Features (1) Simplicity Garbage collection, single inheritance, less C/C++. But… you must learn a boatload of classes! Object-oriented Distributed network communication classes Architecture-neutral Interpreted portable

9/21/99www.cs.vt.edu/wwtut/4 Java 1 Features (2) Robust (?) eliminates common bugs: pointers, arrays Secure more so with Java 2 Multithreaded No type system violations Dynamic dynamically load classes over network

9/21/99www.cs.vt.edu/wwtut/5 What’s New in Java 2 Enhanced Security Fine-grained security manager (e.g., grant write access only to a particular file) Digitally signed apps and applets Swing UI components Java 2D API Accessibility API Drag & drop to/from non-Java apps, between Java apps, w/in one Java app Custom cursors

9/21/99www.cs.vt.edu/wwtut/6 What’s New in Java 2 Navigation with keyboard only (w/o mouse) “Collections” – container classes that generalize Vector, Hashtable, Array. Like C++’s Standard Template Library.Standard Template Library Input Methods for Japanese, Chinese, or Korean text Package-level version numbers Enhancements to serialization, RMI, JavaBeans, garbage collection, Java Native Interface, JDBC,

9/21/99www.cs.vt.edu/wwtut/7 What’s New in Java 2 Java Sound API Engine to play back WAV, AIFF, … Java IDL allows CORBA objects to be written in Java Performance improvements See java.sun.com/products/jdk/1.2/docs/- relnotes/features.html for more info.java.sun.com/products/jdk/1.2/docs/- relnotes/features.html

9/21/99www.cs.vt.edu/wwtut/8 Where examples come from… Java in a Nutshell, 2nd Edition Examples: However, this book only covers Java 1.1.

9/21/99www.cs.vt.edu/wwtut/9 Try this now… Construct an HTML page. Page contains a Java applet. Java applet prints “hello world”. (Click here to run example.)here

9/21/99www.cs.vt.edu/wwtut/10 Solution (Ex. 6-1)Ex. 6-1 import java.applet.*; // Don't forget this import statement! import java.awt.*; // Or this one for the graphics! public class FirstApplet extends Applet { // This method displays the applet. // The Graphics class is how you do all drawing in Java. public void paint(Graphics g) { g.drawString("Hello World", 25, 50); } // This example is from the book "Java in a Nutshell, Second Edition". // Written by David Flanagan. Copyright (c) 1997 O'Reilly & Associates. // You may distribute this source code for non-commercial purposes only. // You may study, modify, and use this example for any purpose, as long as // this notice is retained. Note that this example is provided "as is", // WITHOUT WARRANTY of any kind either expressed or implied.

9/21/99www.cs.vt.edu/wwtut/11 Analysis of Code Invoked by HTML page: My First Applet This is the world's simplest applet.

9/21/99www.cs.vt.edu/wwtut/12 Analysis of Code No main() function Function declarations Only class declarations Inherits from pre-defined class in package Package names are (theoretically) globally unique Default: names visible only within package import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/13 Analysis of Code To compile: javac FirstApplet.java Compile creates bytecode: FirstApplet.class import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/14 What is java.applet? Object Java.lang  Component Java.awt  Container  Panel  Applet Java.applet import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/15 What is java.applet? public class Applet extends Panel { … public String getAppletInfo(); public String getParameter( String name); public void init(); //empty public void start(); //empty public void stop(); //empty } import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/16 Where is paint() defined? (It’s not in applet!) Object Java.lang  Component Java.awt  Container  Panel  Applet Java.applet import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/17 paint() is defined in java.awt.Component Object Java.lang  Component Java.awt  Container  Panel  Applet Java.applet public abstract class Component extends Object { … public void paint(Graphics g); //empty } import java.applet.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/18 What is java.awt.graphics? Object Java.lang  Graphics Java.awt public abstract class Graphics extends Object { … public abstract void drawLine(int x1, int y1, int x2,int y2); public abstract void drawOval(int x, int y, int w, int h); public void drawString(String, int x, int y); public void fillOval(int x, int y, int w, int h); public void setColor(Color c); public void setFont(Font c); } public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString( "Hello World", 25, 50); }

9/21/99www.cs.vt.edu/wwtut/19 What does entire java.awt look like? Show diagram on transparency

9/21/99www.cs.vt.edu/wwtut/20 Example 2… Variation on Hello Word

9/21/99www.cs.vt.edu/wwtut/21 Code import java.applet.*; import java.awt.*; public class SecondApplet extends Applet { static final String message = "Hello World"; private Font font; public void init() { font = new Font("Helvetica", Font.BOLD, 48); } public void paint(Graphics g) { // The pink oval g.setColor(Color.pink); g.fillOval(10, 10, 330, 100); // Red outline. Simulate // 4-pixel wide line g.setColor(Color.red); g.drawOval(10,10, 330, 100); g.drawOval(9, 9, 332, 102); g.drawOval(8, 8, 334, 104); g.drawOval(7, 7, 336, 106); // The text g.setColor(Color.black); g.setFont(font); g.drawString(message, 40, 75); } // This example is from the book "Java in a Nutshell, Second Edition". // Written by David Flanagan. Copyright (c) 1997 O'Reilly & Associates. // You may distribute this source code for non-commercial purposes only. // You may study, modify, and use this example for any purpose, as long as // this notice is retained. Note that this example is provided "as is", // WITHOUT WARRANTY of any kind either expressed or implied.

9/21/99www.cs.vt.edu/wwtut/22 Analysis of Code String is a class, not char array each char is 16-bit unicode Font, Color are classes import java.applet.*; import java.awt.*; public class SecondApplet extends Applet { static final String message = "Hello World"; private Font font; public void init() { font = new Font("Helvetica", Font.BOLD, 48); } public void paint(Graphics g) { // The pink oval g.setColor( Color.pink );

9/21/99www.cs.vt.edu/wwtut/23 What is java.awt.Color? Object Java.lang  Color Java.awt public final class Color extends Object { public Color(int r, int g, int b); public Color(int rgb); public Color(float r, float g, float b);.. public final static Color pink; } g.setColor( Color.pink );

9/21/99www.cs.vt.edu/wwtut/24 What is java.awt.Font? Object Java.lang  Font Java.awt public class Font extends Object { public Font(String name, int style, int size); public final static int BOLD; // or ITALIC, PLAIN... } font = new Font("Helvetica", Font.BOLD, 48);

9/21/99www.cs.vt.edu/wwtut/25 Recall java.awt.graphics… Object Java.lang  Graphics Java.awt public abstract class Graphics extends Object { … public abstract void drawLine(int x1, int y1, int x2,int y2); public abstract void drawOval(int x, int y, int w, int h); public void drawString(String, int x, int y); public void fillOval(int x, int y, int w, int h); public void setColor(Color c); public void setFont(Font c); } g.setColor(Color.pink); g.fillOval(10, 10, 330, 100);... g.setColor(Color.red); g.drawOval(10,10, 330, 100);... g.setFont(font);