Chapter 2: Color and Applets Coming up: Introduction to Graphics.

Slides:



Advertisements
Similar presentations
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.
Advertisements

LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Lecture # 11 JavaScript Graphics. Scalable Vector Graphics (SVG) Scalable Vector Graphics (SVG), as the name implies, are - scalable (without pixelation):
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Outline Graphics Applets Drawing Shapes Components and Containers Images.
© 2004 Pearson Addison-Wesley. All rights reserved2-1 Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics.
2 Data and Expressions Software Solutions Lewis & Loftus java
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
 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.
Chapter 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Primitive Types vs. Reference Types Variables of primitive types hold the values of the primitive types directly. Variables of reference types hold references.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
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.
COMP 14: Files and Graphics for Applets June 19, 2000 Nick Vallidis.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
COMP 14: Applets June 21, 2000 Nick Vallidis. Announcements zP6 is due Friday.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
1 L44 Introduction to Java Applets. 2 OBJECTIVES  To differentiate between applets and applications.  To observe some of Java's exciting capabilities.
Chapter Day 4. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 4 Return Signed Contracts Questions from last Class?? Problem set 1 Posted.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
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.
A Simple Applet.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Standard Graphics in Java,
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
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.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
1 Objects and Primitive Data  Now we can explore some more fundamental programming concepts  Chapter 2 focuses on: predefined objects primitive data.
Chapter 2 Data and Expressions Part Two. 2-2/30 Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive.
Chapter 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
Graphics & Applets CSC 1051 – Data Structures and Algorithms I
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
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 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Chapter 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 2 Data and Expressions 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights.
Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 2 Data and Expressions 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Intro to Graphics from Chapter 2 of Java Software Solutions
Graphics Applets By Mr. Dave Clausen
Chapter 02 Data and Expressions.
CSC 1051 – Data Structures and Algorithms I
Objects and Classes A class An object (the concept) (the realization)
Introduction to Java Applets
Graphics Applets By Mr. Dave Clausen
Chapter 2 Data and Expressions.
Chapter 2 Data and Expressions.
Data and Expressions Part Two
Outline Character Strings Variables and Assignment
Drawing Shapes (Graphics Class) Creating Objects Packages
Presentation transcript:

Chapter 2: Color and Applets Coming up: Introduction to Graphics

Introduction to Graphics A picture is made up of pixels (picture elements), and each pixel is stored separately The number of pixels used to represent a picture is called the picture resolution The number of pixels that can be displayed by a monitor is called the monitor resolution Coming up: Coordinate Systems

Coordinate Systems Each pixel can be identified using a two-dimensional coordinate system When referring to a pixel in a Java program, we use a coordinate system with the origin in the top-left corner Y X(0, 0) (112, 40) Coming up: Representing Color

Representing Color A black and white picture could be stored using one bit per pixel (0 = white and 1 = black) A colored picture requires more information; there are several techniques for representing colors For example, every color can be represented as a mixture of the three additive primary colors Red, Green, and Blue Each color is represented by three numbers between 0 and 255 that collectively are called an RGB value Coming up: The java.awt.Color Class

The java.awt.Color Class A color in a Java program is represented as an object created from the Color class The Color class also contains several predefined colors, including the following: Object Color.black Color.blue Color.cyan Color.orange Color.white Color.yellow RGB Value 0, 0, 0 0, 0, 255 0, 255, , 200, 0 255, 255, , 255, 0 Coming up: Applets

Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported over the Web and executed using a web browser An applet also can be executed using the appletviewer tool of the Java Software Development Kit or from a webpage An applet doesn't need a main method Instead, there are several special methods that serve specific purposes Coming up: Applets

Applets The paint method, for instance, is executed automatically and is used to draw the applet’s contents 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 Coming up: Applets

Applets The class that defines an applet extends the Applet class This makes use of inheritance, which is explored in more detail in Chapter 8 An applet is embedded into an HTML file using a tag that references the bytecode file of the applet The bytecode version of the program is transported across the web and executed by a Java interpreter that is part of the browser Coming up: The HTML applet Tag

The HTML applet Tag The Einstein Applet Coming up: Drawing Shapes

Drawing Shapes Let's explore some of the methods of the Graphics class that draw shapes in more detail A shape can be filled or unfilled, depending on which method is invoked The method parameters specify coordinates and sizes Shapes with curves, like an oval, are usually drawn by specifying the shape’s bounding rectangle An arc can be thought of as a section of an oval Coming up: Drawing an Oval

Drawing an Oval X Y page.drawOval (175, 20, 50, 80); bounding rectangle Coming up: Lets try it out!

Lets try it out! Create an Applet Add in some shapes Add in some text Set the background color Coming up: Netbeans Notes

Netbeans Notes To run your applet you will need an HTML file. You can create an HTML file in the “default package” in Netbeans To run it you can open the HTML file FROM THE “build/classes” directory You can right-click on the class and run the class (which will start the Java appletviewer) End of presentation