Similar documents
CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Data Representation and Applets

Applets and the Graphics class

Data Representation and Applets

Data Representation and Applets

Graphics Applets. By Mr. Dave Clausen

CS1004: Intro to CS in Java, Spring 2005

Appendix F: Java Graphics

Appendix F: Java Graphics

TWO-DIMENSIONAL FIGURES

Chapter 7 Applets. Answers

Data Representation and Applets

Chapter 2 Exercise Solutions

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Graphics Applets. By Mr. Dave Clausen

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

UNIT -1 JAVA APPLETS

Introduction to Computer Science I

9. APPLETS AND APPLICATIONS

Using the API: Introductory Graphics Java Programming 1 Lesson 8

G51PRG: Introduction to Programming Second semester Applets and graphics

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Chapter 3 - Introduction to Java Applets

Chapter 14: Applets and More

Summary. 962 Chapter 23 Applets and Java Web Start

cs Java: lecture #5

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Lab 3: Work with data (IV)

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

SIMPLE APPLET PROGRAM

Graphics and Painting

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

CHAPTER 2. Java Overview

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

Introduction to Computers and Java

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java Applet Basics. Life cycle of an applet:

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

Building Java Programs

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

Learning objectives: Objects and Primitive Data. Introduction to Objects. A Predefined Object. The print versus the println Methods

MaSH Environment graphics

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

CSC System Development with Java Introduction to Java Applets Budditha Hettige

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphic User Interfaces. - GUI concepts - Swing - AWT

Software Concepts. 2-8 Explain the process of translating and executing a Java program. How might the World Wide Web be involved?

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

PROGRAMMING LANGUAGE 2

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root);

Lecture 7 A First Graphic Program And Data Structures & Drawing

Computer Science 210: Data Structures. Intro to Java Graphics

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Java - Applets. public class Buttons extends Applet implements ActionListener

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Paint Tutorial (Project #14a)

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Unit 3. parameters and graphics

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

Graphics and Java 2D Introduction OBJECTIVES. One picture is worth ten thousand words.

Garfield AP CS. Graphics

Rendering a 3-Dimensional Cube Applet Using Light Weight Java Graphing Library (LWJGL) with Java Swing with NetBeans IDE 6.1

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Week 3. parameters, return, math, graphics

CS177 Recitation. Graphics. Python Programming, 2/e 1

CS335 Graphics and Multimedia

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Building Java Programs

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Java TM Applets. Rex Jaeschke

Java Applet & its life Cycle. By Iqtidar Ali

12/22/11. } Rolling a Six-Sided Die. } Fig 6.7: Rolling a Six-Sided Die 6,000,000 Times

To use CodeWarrior to compile and run prewritten Java programs

Contents 8-1. Copyright (c) N. Afshartous

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CPS122 - OBJECT-ORIENTED SOFTWARE DEVELOPMENT

Lecture Static Methods and Variables. Static Methods

Programming: You will have 6 files all need to be located in the dir. named PA4:

CS2 Advanced Programming in Java note 8

CSC 551: Web Programming. Fall 2001

UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS. To define a class, use the class keyword and the name of the class:

Lecture Static Methods and Variables. Static Methods

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

Turing Graphics Summary

Java - Dates and Threads

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Slide 1 CS 170 Java Programming 1 Object-Oriented Graphics Duration: 00:00:18 Advance mode: Auto

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

Building Java Programs

Graphics and Java2D. Objectives

Transcription:

HTML Links Tutorials http://www.htmlcodetutorial.com/ http://www.w3.org/markup/guide/ Quick Reference http://werbach.com/barebones/barebones.html Applets A Java application is a stand-alone program with a main method A Java applet is a Java program that is intended to transported over the web and executed using a web browser

Applets An applet doesn't have a main method Instead, there are several special methods that serve specific purposes paint method -- automatically executed and is used to draw the applets contents When we write applets, we need to include a couple of import statements: import java.applet.applet; import java.awt.*; Applets An applet is embedded into an HTML file using a tag that references the bytecode file (nameofclass.class) of the applet class It is actually the bytecode version of the program that is transported across the web The applet is executed by a Java interpreter that is part of the browser

Applet Methods Several methods from Applet class that are invoked automatically at certain points in an applet's life init - executed only once when the applet is initially loaded start - called when applet becomes active (when browser loads / returns to the page) stop - called when applet becomes inactive (when browser leaves the page) paint - automatically executed and is used to draw the applets contents Applet Methods The Applet class also contains other methods that generally assist in applet processing getcodebase getdocumentbase getaudioclip getimage

Applets The paint method accepts a parameter that is an object of the Graphics class A Graphics object defines a graphics context on which we can draw shapes and text The Graphics class has several methods for drawing shapes The class that defines the applet extends the Applet class we can use all of the methods in the Applet class as if they were in the class that defines our applet Applets and the Web Basic HTML file for an applet: <html> <body> <applet code = "ClassName.class"> </applet> </body> </html> Can also specify size of applet window <applet code="classname.class" height=200 width=300> </applet> Put the applet HTML file (named something.html) and your Java applet bytecode (named ClassName.class) in your public_html folder.

The Color Class A color is defined in a Java program using an object created from the Color class (defined in the java.awt package) contains several static predefined colors Every graphics context has a current foreground color Every drawing surface has a background color Representing Color A color picture requires more information every color can be represented as a mixture of the three primary colors red, green, and blue In Java, each color is represented by three numbers between 0 and 255 that are collectively called an RGB value 1 byte (8 bits) to store the contribution of each color (red, green, blue) Carolina Blue: R 172 G 194 B 227

Drawing Shapes Graphics class is defined in the java.awt package drawarc drawline drawoval drawrect drawstring fillarc filloval fillrect getcolor setcolor Drawing Shapes A shape can be filled or unfilled, depending on which method is invoked The method parameters specify coordinates and sizes Many shapes with curves, like an oval, are drawn by specifying its bounding rectangle An arc can be thought of as a section of an oval

Coordinate Systems Each pixel can be identified using a two-dimensional coordinate system In Java, we use a coordinate system with the origin in the upper left corner (0, 0) 112 X 40 (112, 40) Y Drawing a Line 10 150 X 20 45 page is a Graphics object Y page.drawline (10, 20, 150, 45); or page.drawline (150, 45, 10, 20);

Drawing a Rectangle 50 X 20 40 100 Y page.drawrect (50, 20, 100, 40); Drawing an Oval 175 X 20 80 Y bounding rectangle 50 page.drawoval (175, 20, 50, 80); page.drawarc (175, 20, 50, 80, 0, 90);

Want to Learn More? Creating a GUI with Swing http://java.sun.com/docs/books/tutorial/uiswing/ Creating Applets http://java.sun.com/docs/books/tutorial/applet/