Drawing rectangles and ovals in the Applet window Displaying Text in the Java Console Window Demo of the HelloAgain program Arithmetic expressions Examples.

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
Advertisements

Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
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.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
 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.
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.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
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.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
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.
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.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
©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.
Agenda For Feb Discussion (Assignments & Rubric) 2. PowerPoint Presentation (Drawing Basic Shapes). 4.Read Unit 3 carefully (pages ) then.
© 2007 Lawrenceville Press Slide 1 Chapter 2 HTML An example HTML document Hello world!
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
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.
Exposure Java-A 2006 Chapter 4 Slides Using Methods and Parameters
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.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
CPS Today’s topics Java Applications Graphics Upcoming Review for Midterm Exam Reading Great Ideas, Chapters 5.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Lab 7: Tree & Forest. Drawing a Forest Created by Emily Hill & Jerry Alan Fails.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
SC Introduction to Programming Lecture 1: 5 th May 2003.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
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.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
Creating a Java Application and Applet
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.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
IT11 Agenda for Feb Golden Rule Reminder. 2. PowerPoint demonstration on the structure of Java Applet programs. Source Files HTML Files Class Files.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Introduction to programming in java
Monday 26th May Java Lecture 10 Overview
Object Oriented Programming
Building Java Programs
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Building Java Programs
Building Java Programs
Today’s topics Java Applications Upcoming Reading Graphics
CS110D Programming Language I
February , 2009 CSE 113 B.
Handout-14 Applets and Graphics
Presentation transcript:

Drawing rectangles and ovals in the Applet window Displaying Text in the Java Console Window Demo of the HelloAgain program Arithmetic expressions Examples Wednesday 7 th May, 2003 Java Lecture 2: Overview

Labs 15% (Not 25) Test 20% (Not 10) Final Exam 65% Lectures Final exam HomeworkFinal exam Labwork Final exam Important Note 1

Important Note 2 You must gain a pass in BOTH Practical work 15/15 AND Theory (Test + exam) 37/75  fail

Important Note 3 Friday’s lecture –Lab08 given out and discussed –Demos –Please bring your Explorer’s guide

Statements: g.drawString( " Hello Again ", 70, 180); Parameters: the 3 items inside the brackets are parameters Comments: –One line comments, e.g. // A trivial program to display Hello Again –Multiple line comments, e.g. /* A trivial program to display Hello Again on the computer screen */ Programs consist of Statements and Comments in a particular order.

Drawing Lines p15 // Draw a line from the origin to the point (100, 100) g.drawLine( 0, 0, 100, 100 ); // Draw a line from the point (10,5) to (16, 5) g.drawLine( 10,5, 16,5 ); NOTE: NOT 16

Exercise 2 p 17 What is the output of this program segment? Use a sheet of squared paper to help you find out. g.drawLine( 40, 100, 130, 50 ); g.drawLine( 130, 50, 130, 150 ); g.drawLine( 130, 150, 40, 100 ); g.drawLine( 160, 100, 70, 50 ); g.drawLine( 70, 50, 70, 150 ); g.drawLine( 70, 150, 160, 100 );

Drawing Rectangles p18 g.drawRect(left, top, width, height); Example: g.drawRect( 50, 60, 100, 70 );

Note the order of the parameters g.drawRect(left, top, width, height); g.setColor(Color.red); g.fillRect(left, top, width, height); height top width left

Note the order of the parameters g.drawRect(left, top, width, height); g.setColor(Color.red); g.fillRect(left, top, width, height); height top width left

Drawing Ovals (and circles) p20 g.drawOval(left, top, width, height); Example: g.drawOval( 50, 60, 100, 70 );

Drawing Ovals (and circles) p20 g.fillOval(left, top, width, height); Example: g.fillOval( 50, 60, 100, 70 );

Desk Checking and Testing p25 (i)Start by drawing (accurate) diagrams in pencil on squared paper. (ii) Check the keywords (iii) Check carefully: the order of all parameters and the values of all parameters. (iv) Enter and test your program a few lines at a time. At the worst, comment out sections of the program by putting in /* and */

List of Terms for Chapter 1 p26 Comment10 (9) Coordinates11(10) drawLine16 (15) drawOval21 (20) drawRect19 (18) drawString12 (11) Font13 (12) Output9 (8) parameter14 (13) Pixel11 (10) Program7 setColor23 (22) Statement 7

Chapter 2: Displaying Text in the Java Console Window FirstHello.java: Explorer’s Guide p30 Chapter 2: Displaying Text in the Java Console Window FirstHello.java: Explorer’s Guide p30 Now let us look at the program in the HelloAgain.java file: import java.awt.*; import java.applet.Applet; public class FirstHello extends Applet{ public void init() { // * * * * * * * * * * * * * * * * * * * * * // A Trivial program that displays a string in // the Java Console window System.out.println("Hello Computer Again"); // * * * * * * * * * * * * * * * * * * * * * }

A string is any sequence of characters on the screen. To display the string: Hello Computer on the screen –The command we used was: System.out.println(“Hello Computer”); What will be displayed if we use the following lines? System.out.println(“Junk”); System.out.println“^&*(*”); System.out.println(“6 + 6 = 200”); Notice that the quotes do not appear on the screen. Displaying Strings

Order of Program Execution Statements are executed one after another

import java.awt.*; import java.applet.Applet; public class ScrambledEggs extends Applet{ public void init() { // * * * * * * * * * * * * * * * * * * * * * * * * * * * /* Program to give instructions on how to make scrambled eggs System.out.println(); System.out.println"Whisk"); System.out.prntln("Break eggs into bowl) system.out.println('Cook gently'); // * * * * * * * * * * * * * * * * * * * * * * * * * * * Exercise 2 Bad Eggs E.G. p35 There are at least 8 mistakes in this program

We can instruct the computer to do arithmetic for us. We shall begin by using only integers: (numbers with no fractional part, e.g. 23, 1990, 0, -899). Numbers must NOT be enclosed in quote marks if they are to be used in calculations. Arithmetic Expressions E. G. p40

Unlike strings numbers must not be enclosed in quotes! Arithmetic operators +plus -minus * multiplication / division

Expressions E. G. p41 // Program to show how integers can be used // in arithmetic expressions System.out.println(); System.out.println(200); System.out.println( ); System.out.println( );  System.out.println(4 * 5 + 6);  System.out.println(4 * (5 + 6)); System.out.println("4 * 5 = " + (4 * 5));

First, any expressions in brackets are evaluated Then any multiplications or divisions are evaluated (from left to right, taking account of brackets) Then any additions or subtractions are evaluated (from left to right again), thus arriving at the value of the expression. Order of Evaluating Expressions E. G. p41

Needed for changing the order in which the computer will evaluate an expression. If an expression follows a string you should enclose it in brackets. For example:. System.out.println( " = " ) --->? System.out.println( " = " + (2 + 3)) --->? We also use brackets to make our expressions clearer to read. Brackets

Homework Finish reading all Chapter 1 of the Explorers Guide Do as many exercises in Chapter 1 as you can. Read Chapter 2, pages 28 – 40 Do as many Chapter 2 exercises as you can. Bring any questions to Friday’s lecture

Drawing Ovals (and circles) p20 g.drawOval(left, top, width, height); Example: g.drawOval( 50, 60, 100, 70 );