Java Keywords Java has special keywords that have meaning in Java. You have already seen a fair amount of keywords. Examples are: public, main, System,

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
Review of Math Class Methods abssqrt minmax powround ceilfloor.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Objects, Variables & Methods Java encapsulates data and action modules that access the data in one container, called an object. Object members that.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
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.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
 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.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
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.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
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.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
A Simple Applet.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
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).
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original (non-OOP)
// Java0802.java // CardDeck Case Study #02 // Variables, called attributes or data fields, are added to the class. public class Java0802 { public static.
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
// Java0601.java // This program demonstrates that the methods of a class are not always // accessible, like they were with the class. In this case an.
Exposure Java-A 2006 Chapter 4 Slides Using Methods and Parameters
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
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.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Introductory Graphics Chapter Three. Computer Graphics §Full motion pictures (“Star Wars”) l animated films §Virtual reality §Games §Simulators (air craft.
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.
Creating a Java Application and Applet
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.
Building Java Programs Graphics Reading: Supplement 3G.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Java Keywords Java has special keywords that have meaning in Java. You have already seen a fair amount of keywords. Examples are: public, main, System,
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.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
CS 112 Introduction to Programming Java Graphics Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
Java Applets Getting Started. Import Files In order to run the applet properly, we have to import some files into our class. These files are: –import.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Review of Math Class Methods abssqrt minmax powround ceilfloor.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
PowerPoint Presentation Authors of Exposure Java
Working with Text and Numbers in Java
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Section 6.2 Classes & Objects.
Chapter 1 Introducing Small Basic
Presentation transcript:

Java Keywords Java has special keywords that have meaning in Java. You have already seen a fair amount of keywords. Examples are: public, main, System, int, double, print, void and there will be many more you will learn during this course.

Comparing English & Java EnglishJava ComponentExampleComponentExample wordtigerkeywordpublic sentenceThe tiger is big.program statement System.out.print("The tiger is big."); paragraphMy sister and I went to the zoo. We saw many animals. The tigers were very scary. They were large, very loud and they smelled bad. We liked the funny monkeys better. methodpublic static void main(String args[]) { int a = 100; int b = 200; int sum = a + b; System.out.println(sum); } chapter or essay Our Trip to the Zoo Opening paragraph Middle paragraphs Closing paragraph classpublic class Demo { public static void main(String args[]) { System.out.println("Hello"); }

Fundamental Java Syntax Rules  All program statements end with a semi-colon.  All program statements are contained in a method.  All methods are contained in a class.  Each method must have a heading.  Each class must have a heading.  Class and method containers start with a { brace.  Class and method containers end with a } brace.  Method headings and class headings are not program statements and they do not get a semi-colon.  All keywords in Java are case-sensitive. This means that System and system are two different words.  Comments, which are not program statements, start with two slashes and do not require a semi-colon. Examples of these rules are shown on the next slide.

Fundamental Java Syntax Rules Program Example: public class Example// class, called Example, heading {// start of the Example class container public static void main (String args[])//method, called main, heading {//start of the main method container int a = 10;//program statement int b = 25;//program statement System.out.println();//program statement System.out.println(a);//program statement System.out.println(b);//program statement System.out.println();//program statement }//end of the main method container }//end of the Example class container

The Toolbox Analogy A class is like a toolbox. A class can have several methods just like a toolbox can have several tools. Before any of these tools can be used, you must first find the toolbox that they are in.

// Java0401.java // This program shows how to use the method of the Math // class. The Math class is part of the java.lang package, which is // automatically loaded (imported) by the compiler. // Math.sqrt returns the square root of the argument. public class Java0401 { public static void main (String args[]) { System.out.println("\nJAVA0401.JAVA\n"); int n1 = 625; double n2 = 6.25; System.out.println("Square root of " + n1 + ": " + Math.sqrt(n1) ); System.out.println("Square root of " + n2 + ": " + Math.sqrt(n2) ); System.out.println(); } JAVA0401.JAVA Square root of 625: 25.0 Square root of 6.25: 2.5

// Java0401.java // This program shows how to use the method of the Math // class. The Math class is part of the java.lang package, which is // automatically loaded (imported) by the compiler. // Math.sqrt returns the square root of the argument. public class Java0401 { public static void main (String args[]) { System.out.println("\nJAVA0401.JAVA\n"); int n1 = -625; double n2 = 6.25; System.out.println("Square root of " + n1 + ": " + Math.sqrt(n1)); System.out.println("Square root of " + n2 + ": " + Math.sqrt(n2)); System.out.println(); } Try This! Change the value of n1 from 625 to Recompile and execute and see what happens.

// Java0401.java // This program shows how to use the method of the Math // class. The Math class is part of the java.lang package, which is // automatically loaded (imported) by the compiler. // Math.sqrt returns the square root of the argument. public class Java0401 { public static void main (String args[]) { System.out.println("\nJAVA0401.JAVA\n"); int n1 = -625; double n2 = 6.25; System.out.println("Square root of " + n1 + ": " + Math.sqrt(n1)); System.out.println("Square root of " + n2 + ": " + Math.sqrt(n2)); System.out.println(); } NOTE: NaN means “ N ot A N umber”. Remember the square root of a negative number is not a real number. JAVA0401.JAVA Square root of -625: NaN Square root of 6.25: 2.5

Class Method Syntax Math.sqrt(n1) 1. Math is the class identifier, which contains the methods you call. 2.  separates the class identifier from the method identifier 3. sqrt is the method identifier 4. (n1) n1 is the argument or parameter passed to the method

// Java0402.java // This program shows different arguments that can be used with the // method. Note how a method call can be the argument of another method call. public class Java0402 { public static void main (String args[]) { System.out.println("\nJAVA0402.JAVA\n"); double n1, n2, n3, n4; n1 = Math.sqrt(1024);// constant argument n2 = Math.sqrt(n1);// variable argument n3 = Math.sqrt(n1 + n2); // expression argument n4 = Math.sqrt(Math.sqrt(256)); // method argument System.out.println("n1: " + n1); System.out.println("n2: " + n2); System.out.println("n3: " + n3); System.out.println("n4: " + n4); System.out.println(); } JAVA0402.JAVA n1: 32.0 n2: n3: n4: 4.0

Method Arguments or Parameters The information, which is passed to a method is called an argument or a parameter. Parameters are placed between parentheses immediately following the method identifier. Parameters can be constants, variables, expressions or they can be methods. The only requirement is that the correct data type value is passed to the method. In other words, Math.sqrt(x ) can compute the square root of x, if x stores any non-negative number ( int or double ), but not if x stores a String value like "aardvark".

// Java0403.java // This program demonstrates the and methods. // The method returns the truncation down to the next lower integer. // The method returns the next higher integer. // The method rounds the argument and returns the closest integer. public class Java0403 { public static void main (String args[]) { System.out.println("\nJAVA0403.JAVA\n"); System.out.println("Math.floor(5.001): " + Math.floor(5.001)); System.out.println("Math.floor(5.999): " + Math.floor(5.999)); System.out.println("Math.floor(5.5) : " + Math.floor(5.5)); System.out.println("Math.floor(5.499): " + Math.floor(5.499)); System.out.println(); System.out.println("Math.ceil(5.001) : " + Math.ceil(5.001)); System.out.println("Math.ceil(5.999) : " + Math.ceil(5.999)); System.out.println("Math.ceil(5.5) : " + Math.ceil(5.5)); System.out.println("Math.ceil(5.499) : " + Math.ceil(5.499)); System.out.println(); System.out.println("Math.round(5.001): " + Math.round(5.001)); System.out.println("Math.round(5.999): " + Math.round(5.999)); System.out.println("Math.round(5.5) : " + Math.round(5.5)); System.out.println("Math.round(5.499): " + Math.round(5.499)); System.out.println(); }

JAVA0403.JAVA Math.floor(5.001): 5.0 Math.floor(5.999): 5.0 Math.floor(5.5) : 5.0 Math.floor(5.499): 5.0 Math.ceil(5.001) : 6.0 Math.ceil(5.999) : 6.0 Math.ceil(5.5) : 6.0 Math.ceil(5.499) : 6.0 Math.round(5.001): 5 Math.round(5.999): 6 Math.round(5.5) : 6 Math.round(5.499): 5

// Java0404.java // This program demonstrates the and methods. // returns the largest value of the two arguments. // returns the smallest value of the two arguments. public class Java0404 { public static void main (String args[]) { System.out.println("\nJAVA0404.JAVA\n"); System.out.println("Math.max(100,200):" + Math.max(100,200)); System.out.println("Math.max(-10,-20): " + Math.max(-10,-20)); System.out.println("Math.max(500,500):" + Math.max(500,500)); System.out.println(); System.out.println("Math.min(100,200): " + Math.min(100,200)); System.out.println("Math.min(-10,-20): " + Math.min(-10,-20)); System.out.println("Math.min(500,500): " + Math.min(500,500)); System.out.println(); } JAVA0404.JAVA Math.max(100,200): 200 Math.max(-10,-20): -10 Math.max(500,500): 500 Math.min(100,200): 100 Math.min(-10,-20): -20 Math.min(500,500): 500

// Java0405.java // This program demonstrates the and methods. // Math.abs returns the absolute value of the argument. // Math.pow returns the first argument raised to the power // of the second argument. public class Java0405 { public static void main (String args[]) { System.out.println("\nJAVA0405.JAVA\n"); System.out.println("Math.abs(-25): " + Math.abs(-25)); System.out.println("Math.abs(100): " + Math.abs(100)); System.out.println("Math.abs(0) : " + Math.abs(0)); System.out.println(); System.out.println("Math.pow(3,4) : " + Math.pow(3,4)); System.out.println("Math.pow(-2,2): " + Math.pow(-2,2)); System.out.println("Math.pow(2,-2): " + Math.pow(2,-2)); System.out.println(); } 3 4 = 81 (-2) 2 = = = ¼ = JAVA0405.JAVA Math.abs(-25): 25 Math.abs(100): 100 Math.abs(0) : 0 Math.pow(3,4) : 81.0 Math.pow(-2,2): 4.0 Math.pow(2,-2): 0.25

// Java0406.java // This program demonstrates the and fields of the // class. // Both and are "final" attributes of the class. // and are not methods. Note there are no parentheses. public class Java0406 { public static void main (String args[]) { System.out.println("\nJAVA0406.JAVA\n"); System.out.println("Math.PI: " + Math.PI ); System.out.println("Math.E : " + Math.E ); System.out.println(); } JAVA0406.JAVA Math.PI: Math.E :

What is the Expo class? The first thing you need to know about the Expo class is that it is a special class that has been created by the Schrams. It is NOT part of standard Java.

Not Part of Standard Java! What are the Schrams up to? Several topics, even simple topics, in Java have a rather complicated and confusing syntax – especially for beginning programmers. The Expo class (as in Exposure Java) is designed to make programming simpler – allowing us to focus on the concepts without getting bogged down in complicated syntax.

Learning Graphics Programming Learning graphics programming is not simply a fun issue. You will learn many sophisticated computer science concepts by studying graphics programs. Some of the most sophisticated programs are video games. Only very dedicated and knowledgeable programmers can write effective video games.

Graphics & Coordinate Geometry A graphics window uses a system of (X,Y) coordinates in a manner similar to the use of coordinates that you first learned in your math classes. The next slide shows an example of the Cartesian Coordinate System. In particular, note that the Cartesian system has four quadrants with the (0,0) coordinate (called the "origin") located in the center of the grid where the X-Axis and the Y-Axis intersect.

Cartesian Coordinate Graph

Computer Graphics Window

// Java0407.java // This demonstrates the drawPixel and drawPoint methods of the Expo class. import java.awt.*; import java.applet.*; public class Java0407 extends Applet { public void paint(Graphics g) { Expo.drawPixel(g,100,200); Expo.drawPixel(g,200,200); Expo.drawPixel(g,300,200); Expo.drawPixel(g,400,200); Expo.drawPixel(g,500,200); Expo.drawPixel(g,600,200); Expo.drawPixel(g,700,200); Expo.drawPixel(g,800,200); Expo.drawPixel(g,900,200); Expo.drawPoint(g,100,400); Expo.drawPoint(g,200,400); Expo.drawPoint(g,300,400); Expo.drawPoint(g,400,400); Expo.drawPoint(g,500,400); Expo.drawPoint(g,600,400); Expo.drawPoint(g,700,400); Expo.drawPoint(g,800,400); Expo.drawPoint(g,900,400); }

// Java0407.java // This demonstrates the drawPixel and drawPoint methods of the Expo class. import java.awt.*; import java.applet.*; public class Java0407 extends Applet { public void paint(Graphics g) { Expo.drawPixel(g,100,200); Expo.drawPixel(g,200,200); Expo.drawPixel(g,300,200); Expo.drawPixel(g,400,200); Expo.drawPixel(g,500,200); Expo.drawPixel(g,600,200); Expo.drawPixel(g,700,200); Expo.drawPixel(g,800,200); Expo.drawPixel(g,900,200); Expo.drawPoint(g,100,400); Expo.drawPoint(g,200,400); Expo.drawPoint(g,300,400); Expo.drawPoint(g,400,400); Expo.drawPoint(g,500,400); Expo.drawPoint(g,600,400); Expo.drawPoint(g,700,400); Expo.drawPoint(g,800,400); Expo.drawPoint(g,900,400); } The pixels may be difficult to see. The points should be easier to see.

The drawLine Method Expo.drawLine(g, x1, y1, x2, y2); Draws a line from coordinate (x1,y1) to coordinate (x2,y2) x1, y1 x2, y2

// Java0408.java // This program demonstrates the drawLine method of the Expo class. // Lines are drawn from (X1,Y1) to (X2,Y2) with drawLine(g,X1,Y1,X2,Y2) import java.awt.*; import java.applet.*; public class Java0408 extends Applet { public void paint(Graphics g) { Expo.drawLine(g,100,100,900,550); Expo.drawLine(g,100,550,900,100); Expo.drawLine(g,100,325,900,325); Expo.drawLine(g,500,100,500,550); }

jGRASP and Applets: Behind the Scenes An applet is a Java program that is designed to execute inside a web page. In order for this to work, you need an.html file. HTML is the language of the internet. Whenever you execute an applet in jGRASP, it actually creates the necessary HTML file for you. The temporary file is called jgrasphta.html

Remember this? When you first set up jGRASP one of the settings was specifically for HTML. We changed the values of width to 1000 and height to 650.

Try This! Open a Web browser.

Press - to Open a file and click Browse.

Press OK.

Click Allow blocked content.

You might see a message like this. If you do, just click Run.

Even if you “Allow blocked content” and click “Run” you may still get this message. This means your computer’s security settings will not allow a Java program to execute in a browser. If that is the case, do not be concerned. We will be executing our applets with AppleViewer via jGRASP.

The drawRectangle Method Expo.drawRectangle(g, x1, y1, x2, y2); Draws a rectangle with a top-left corner at coordinate (x1,y1) and a bottom-right hand corner of (x2,y2). x1, y1 x2, y2

// Java0409.java // This program demonstrates the drawRectangle method of the Expo class. // Rectangles are drawn from the upper-left-hand corner(X1,Y1) to the // lower-right-hand corner(X2,Y2) with drawRectangle(g,X1,Y1,X2,Y2). import java.awt.*; import java.applet.*; public class Java0409 extends Applet { public void paint(Graphics g) { Expo.drawRectangle(g,100,100,200,200); Expo.drawRectangle(g,400,100,900,200); Expo.drawRectangle(g,100,300,900,600); Expo.drawRectangle(g,200,400,400,500); Expo.drawRectangle(g,600,400,800,500); }

The drawCircle Method Expo.drawCircle(g, centerX, centerY, radius); The location of the circle is specified in its center (centerX,centerY) and the size is specified by the radius. centerX, centerY radius

// Java0410.java // This program demonstrates the drawCircle method of the Expo class. // Circles are drawn from their center (X,Y) with a particular radius // with drawCircle(g,X,Y,radius). import java.awt.*; import java.applet.*; public class Java0410 extends Applet { public void paint(Graphics g) { Expo.drawCircle(g,150,150,100); Expo.drawCircle(g,1000,0,200); Expo.drawCircle(g,500,325,100); Expo.drawCircle(g,500,325,200); Expo.drawCircle(g,200,500,80); Expo.drawCircle(g,800,500,120); }

The drawOval Method Expo.drawOval (g, centerX, centerY, horizontal radius, vertical radius); The location of the oval is specified in its center (centerX,centerY) and the size is specified by the 2 radii. centerX, centerY h radiusv radius

// Java0411.java // This program demonstrates the drawOval method of the Expo class. // Ovals are drawn from their center (X,Y) with a horizontal radius (hr) // and a vertical radius (vr) with drawOval(g,X,Y,hr,vr). import java.awt.*; import java.applet.*; public class Java0411 extends Applet { public void paint(Graphics g) { Expo.drawOval(g,150,150,100,100); Expo.drawOval(g,900,325,100,300); Expo.drawOval(g,600,150,200,60); Expo.drawOval(g,500,325,40,100); Expo.drawOval(g,500,325,100,40); Expo.drawOval(g,200,500,80,120); Expo.drawOval(g,600,500,120,80); }

Drawing Arcs An arc is a piece of an oval. In order to draw an “arc” you need specify where the arc starts and where it stops. 0°, 360° 30° 60° 90° 120° 150° 180° 210° 240° 270° 300° 330°

The drawArc Method Expo.drawArc(g, centerX, centerY, horizontal radius, vertical radius, start, finish); Draws part of an oval. The 1 st 5 parameters are the same as Expo.drawOval. Start indicates the degree location of the beginning of the arc. Finish indicates the degree location of the end of the arc. centerX, centerY start finish h radiusv radius

// Java0412.java // This program demonstrates the drawArc method of the Expo class. // An "arc" is a piece of an "oval". // Like ovals, arcs are drawn from their center (X,Y) with a horizontal radius (hr) // and a vertical radius (vr). Arcs also require a starting and stopping degree value. //This is done with drawArc(g,X,Y,hr,vr,start,stop). import java.awt.*; import java.applet.*; public class Java0412 extends Applet { public void paint(Graphics g) { Expo.drawArc(g,500,325,400,300,0,360);// complete oval Expo.drawArc(g,500,400,200,50,90,270); // bottom half of an oval Expo.drawArc(g,500,400,200,100,90,270); Expo.drawArc(g,350,200,80,20,270,90); // top half of an oval Expo.drawArc(g,650,200,80,20,270,90); Expo.drawArc(g,123,325,100,100,180,0); // left half of an oval Expo.drawArc(g,878,325,100,100,0,180); // right half of an oval Expo.drawArc(g,490,325,10,20,270,360); // top-left 1/4 of an oval Expo.drawArc(g,510,325,10,20,0,90); // top-right 1/4 of an oval Expo.drawArc(g,70,325,20,30,180,90); // 3/4 of an oval Expo.drawArc(g,930,325,20,30,270,180); // different 3/4 of an oval Expo.drawPoint(g,350,200); Expo.drawPoint(g,650,200); }

Parameter Order centerX, centerY finish start v radius h radius Expo.drawArc(g, centerX, centerY, horizontal radius, vertical radius, start, finish); Parameter order is VERY significant !!!!!!! Simply switching the order of the start and finish parameters causes a completely different arc to be drawn. The next program will graphically demonstrate what happens when parameters are out of order.

// Java0413.java // This repeats the previous program which drew the smiley face. // The program demonstrates what happens parameters are put in the wrong order. // The program might compile and execute, but the results are not what you expect. import java.awt.*; import java.applet.*; public class Java0413 extends Applet { public void paint(Graphics g) { Expo.drawArc(g,325,500,400,300,0,360); Expo.drawArc(g,500,400,50,200,90,270); Expo.drawArc(g,400,500,200,100,270,90); Expo.drawArc(g,200,350,20,80,270,90); Expo.drawArc(g,650,200,80,20,90,270); Expo.drawArc(g,123,325,100,100,0,180); Expo.drawArc(g,878,325,100,100,180,0); Expo.drawArc(g,490,325,10,20,270,360); Expo.drawArc(g,325,510,10,20,90,0); Expo.drawArc(g,325,70,20,30,90,270); Expo.drawArc(g,930,325,30,20,270,180); Expo.drawPoint(g,200,350); Expo.drawPoint(g,650,200); }

Parameter Sequence Matters Java0412.java vs. Java0413.java Expo.drawArc(g,500,325,400,300,0,360); Expo.drawArc(g,500,400,200,50,90,270); Expo.drawArc(g,500,400,200,100,90,270); Expo.drawArc(g,350,200,80,20,270,90); Expo.drawArc(g,650,200,80,20,270,90); Expo.drawArc(g,123,325,100,100,180,0); Expo.drawArc(g,878,325,100,100,0,180); Expo.drawArc(g,490,325,10,20,270,360); Expo.drawArc(g,510,325,10,20,0,90); Expo.drawArc(g,70,325,20,30,180,90); Expo.drawArc(g,930,325,20,30,270,180); Expo.drawPoint(g,350,200); Expo.drawArc(g,325,500,400,300,0,360); Expo.drawArc(g,500,400,50,200,90,270); Expo.drawArc(g,400,500,200,100,270,90); Expo.drawArc(g,200,350,20,80,270,90); Expo.drawArc(g,650,200,80,20,90,270); Expo.drawArc(g,123,325,100,100,0,180); Expo.drawArc(g,878,325,100,100,180,0); Expo.drawArc(g,490,325,10,20,270,360); Expo.drawArc(g,325,510,10,20,90,0); Expo.drawArc(g,325,70,20,30,90,270); Expo.drawArc(g,930,325,30,20,270,180); Expo.drawPoint(g,200,350);

The fillRectangle Method Expo.fillRectangle(g, x1, y1, x2, y2); Draws a SOLID (filled in) rectangle with a top-left corner at coordinate (x1,y1) and a bottom-right hand corner of (x2,y2). x1, y1 x2, y2

// Java0414.java // This program demonstrates the fillRectangle method of the Expo class. // The parameters are the same as drawRectangle. // Even though 5 solid rectangles are drawn, only 3 show up on the screen. // Where are the other 2? import java.awt.*; import java.applet.*; public class Java0414 extends Applet { public void paint(Graphics g) { Expo.fillRectangle(g,100,100,200,200); Expo.fillRectangle(g,400,100,900,200); Expo.fillRectangle(g,100,300,900,600); Expo.fillRectangle(g,200,400,400,500); Expo.fillRectangle(g,600,400,800,500); }

drawRectangle & fillRectangle Java0409.java vs. Java0414.java Expo.drawRectangle(g,100,100,200,200); Expo.drawRectangle(g,400,100,900,200); Expo.drawRectangle(g,100,300,900,600); Expo.drawRectangle(g,200,400,400,500); Expo.drawRectangle(g,600,400,800,500); Expo.fillRectangle(g,100,100,200,200); Expo.fillRectangle(g,400,100,900,200); Expo.fillRectangle(g,100,300,900,600); Expo.fillRectangle(g,200,400,400,500); Expo.fillRectangle(g,600,400,800,500); These 2 rectangles do not show up because they are the same color as the rectangle behind them.

// Java0415.java // This program demonstrates the setColor method of the Expo class. import java.awt.*; import java.applet.*; public class Java0415 extends Applet { public void paint(Graphics g) { Expo.fillRectangle(g,100,100,200,200); Expo.fillRectangle(g,400,100,900,200); Expo.fillRectangle(g,100,300,900,600); Expo.setColor(g,Expo.white); Expo.fillRectangle(g,200,400,400,500); Expo.fillRectangle(g,600,400,800,500); }

// Java0416.java // This demonstrates 35 of the 36 colors of the Expo class // There is no white circle drawn since white is the background color. // NOTE: The 7 primary colors in the Expo class are // red, orange, yellow, green, blue, tan and gray. // Each of these colors also has a "dark" shade and a "light" shade. // Example: The 3 shades of red are red, darkRed and lightRed. // There are also 15 special colors which do not have shades: // black, white, brown, violet, purple, turquoise, pink, cyan, // magenta, indigo, teal, gold, silver, bronze and lime. import java.awt.*; import java.applet.*; public class Java0416 extends Applet { public void paint(Graphics g) { int radius = 75; // primary colors Expo.setColor(g,Expo.red);Expo.fillCircle(g, 75, 75,radius); Expo.setColor(g,Expo.orange);Expo.fillCircle(g,200, 75,radius); Expo.setColor(g,Expo.yellow);Expo.fillCircle(g,325, 75,radius); Expo.setColor(g,Expo.green);Expo.fillCircle(g,450, 75,radius); Expo.setColor(g,Expo.blue);Expo.fillCircle(g,575, 75,radius); Expo.setColor(g,Expo.tan);Expo.fillCircle(g,700, 75,radius); Expo.setColor(g,Expo.gray);Expo.fillCircle(g,825, 75,radius);

// dark colors Expo.setColor(g,Expo.darkRed);Expo.fillCircle(g, 75,200,radius); Expo.setColor(g,Expo.darkOrange);Expo.fillCircle(g,200,200,radius); Expo.setColor(g,Expo.darkYellow);Expo.fillCircle(g,325,200,radius); Expo.setColor(g,Expo.darkGreen);Expo.fillCircle(g,450,200,radius); Expo.setColor(g,Expo.darkBlue);Expo.fillCircle(g,575,200,radius); Expo.setColor(g,Expo.darkTan);Expo.fillCircle(g,700,200,radius); Expo.setColor(g,Expo.darkGray);Expo.fillCircle(g,825,200,radius); // light colors Expo.setColor(g,Expo.lightRed);Expo.fillCircle(g, 75,325,radius); Expo.setColor(g,Expo.lightOrange);Expo.fillCircle(g,200,325,radius); Expo.setColor(g,Expo.lightYellow);Expo.fillCircle(g,325,325,radius); Expo.setColor(g,Expo.lightGreen);Expo.fillCircle(g,450,325,radius); Expo.setColor(g,Expo.lightBlue);Expo.fillCircle(g,575,325,radius); Expo.setColor(g,Expo.lightTan);Expo.fillCircle(g,700,325,radius); Expo.setColor(g,Expo.lightGray);Expo.fillCircle(g,825,325,radius); // special colors Expo.setColor(g,Expo.brown);Expo.fillCircle(g, 75,450,radius); Expo.setColor(g,Expo.violet);Expo.fillCircle(g,200,450,radius); Expo.setColor(g,Expo.purple);Expo.fillCircle(g,325,450,radius); Expo.setColor(g,Expo.lime);Expo.fillCircle(g,450,450,radius); Expo.setColor(g,Expo.cyan);Expo.fillCircle(g,575,450,radius); Expo.setColor(g,Expo.pink);Expo.fillCircle(g,700,450,radius); Expo.setColor(g,Expo.black);Expo.fillCircle(g,825,450,radius); Expo.setColor(g,Expo.magenta);Expo.fillCircle(g, 75,575,radius); Expo.setColor(g,Expo.indigo);Expo.fillCircle(g,200,575,radius); Expo.setColor(g,Expo.teal);Expo.fillCircle(g,325,575,radius); Expo.setColor(g,Expo.turquoise);Expo.fillCircle(g,450,575,radius); Expo.setColor(g,Expo.gold);Expo.fillCircle(g,575,575,radius); Expo.setColor(g,Expo.silver);Expo.fillCircle(g,700,575,radius); Expo.setColor(g,Expo.bronze);Expo.fillCircle(g,825,575,radius); }

The setColor Method Expo.setColor(g, Expo.colorName); Sets the graphics display color of the following graphics output to the specified color constant of the Expo class. There are 36 color constants listed below. red orange yellowgreenblue gray tandarkReddarkOrange darkYellow darkGreendarkBlue darkGray darkTan lightRed lightOrange lightYellowlightGreen lightBlue lightGraylightTan blackwhitebrown violetpurpleturquoisepinkcyanmagenta indigotealgoldsilverbronzelime NOTE: You are not limited to only these 36 colors. By combining different amounts of red, green, and blue values, you can create any of over 16 million different colors. At a later time, you will learn how to create more colors.

// Java0417.java // This program demonstrates fillOval and fillArc. import java.awt.*; import java.applet.*; public class Java0417 extends Applet { public void paint(Graphics g) { Expo.fillOval(g,125,150,100,100); Expo.fillArc( g,125,500,100,100,0,90); Expo.fillOval(g,400,150,100,50); Expo.fillArc( g,400,500,100,50,90,270); Expo.fillOval(g,625,150,50,100); Expo.fillArc( g,625,500,50,100,270,180); Expo.setColor(g,Expo.yellow); Expo.fillOval(g,850,150,100,100); Expo.fillArc( g,850,500,100,100,135,45); Expo.setColor(g,Expo.black); Expo.drawLine(g,850,150,950,150); Expo.drawPoint(g,865,90); Expo.drawPoint(g,865,440); }

Important Facts to Remember about the Expo class  The Expo class is not part of any Java standard library.  The class was created to simplify programming and allow students to focus on the logic of programming.  In order to use the Expo class, the file Expo.java must be in the same folder/directory as the.java file that calls the Expo class methods.  The Expo class DOES NOT replace other Java classes that the College Board ® requires us to teach. It is ONLY used when the College Board ® requires us to teach a topic but is NOT concerned with which class we use to teach it.  Students will NOT be required to memorize the methods of the Expo class. They will instead be provided with documentation to use during labs and tests.

This is what you see when you double-click Expo.html. You may have to select “Allow Blocked Content” before everything shows up. Scroll down to see information on all of the Expo class methods.