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.

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.
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.
1 Graphics -- Introduction zThe use of graphics is common among modern software systems  Java has strong API support for graphics in the java.awt (abstract.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
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.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
©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.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
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.
Chapter Day 3. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 3 Return Signed Contracts Questions from last Class?? Problem set 1 Posted.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
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.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
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.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
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
ELC 312 DAY 2. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Agenda Questions? Finish discussion on Object oriented programming Discussion on.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
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.
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.
Intro to Graphics from Chapter 2 of Java Software Solutions
Chapter 02 Data and Expressions.
CSC 1051 – Data Structures and Algorithms I
Objects and Classes A class An object (the concept) (the realization)
title = "Java Software Solutions";
Chapter 2 Data and Expressions.
Graphics -- Introduction
Java Applets.
Chapter 2 Data and Expressions.
Data and Expressions Part Two
Outline Character Strings Variables and Assignment
Drawing Shapes (Graphics Class) Creating Objects Packages
Chapter 2: Objects and Primitive Data
Presentation transcript:

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 components b A picture or drawing must be digitized for storage on a computer b A picture is broken down into pixels, and each pixel is stored separately

2 Representing Color b A black and white picture can be stored using one bit per pixel (0 = white and 1 = black) b A color picture requires more information, and there are several techniques for representing a particular color b For example, every color can be represented as a mixture of the three primary colors Red, Green, and Blue b In Java, each color is represented by three numbers between 0 and 255 that are collectively called an RGB value

3 Coordinate Systems b Each pixel can be identified using a two-dimensional coordinate system b When referring to a pixel in a Java program, we use a coordinate system with the origin in the upper left corner Y X(0, 0) (112, 40)

4 Applets  A Java application is a stand-alone program with a main method (like the ones we've seen so far) b An applet is a Java program that is intended to transported over the web and executed using a web browser b An applet can also be executed using the appletviewer tool of the Java Software Development Kit  An applet doesn't have a main method b Instead, there are several special methods that serve specific purposes  The paint method, for instance, is automatically executed and is used to draw the applets contents

5 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 b The class that defines the applet extends the Applet class b This makes use of inheritance, an object-oriented concept explored in more detail in Chapter 7 b See Einstein.java (page 93) Einstein.java

6 Applets b An applet is embedded into an HTML file using a tag that references the bytecode file of the applet class b It is actually the bytecode version of the program that is transported across the web b The applet is executed by a Java interpreter that is part of the browser

7 Drawing Shapes  Let's explore some of the methods of the Graphics class that draw shapes in more detail b A shape can be filled or unfilled, depending on which method is invoked b The method parameters specify coordinates and sizes b Recall from Chapter 1 that the Java coordinate system has the origin in the upper left corner b Many shapes with curves, like an oval, are drawn by specifying its bounding rectangle b An arc can be thought of as a section of an oval

8 Drawing a Line X Y page.drawLine (10, 20, 150, 45); page.drawLine (150, 45, 10, 20); or

9 Drawing a Rectangle X Y page.drawRect (50, 20, 100, 40);

10 Drawing an Oval X Y page.drawOval (175, 20, 50, 80); boundingrectangle

11 The Color Class  A color is defined in a Java program using an object created from the Color class  The Color class also contains several static predefined colors b Every graphics context has a current foreground color b Every drawing surface has a background color b See Snowman.java (page ) Snowman.java