23-Jun-15 Images. Drawing images Java can display.gif,.jpg (or.jpeg ), and.png images These are the only kinds it can display Displaying them is (relatively)

Slides:



Advertisements
Similar presentations
#8: Try it Out on Users, Then Fix It! Users bring a different context to the situation than do designers (thumbnail plot images provided as a reminder.
Advertisements

Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
Preloading Images for better Performance Using the MediaTracker class.
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.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Exceptions Exception. Exceptions Overview Exceptional Situations Syntax of Try, Catch, Throw Defining and Using Your Own Exceptions.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00.
Graphics Programming UQC117S2 Semester /4. Session 3 1 Drawing in Java 2D Graphics API.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Ten debugging techniques. The execution process Execution proceeds in a standard series of steps Compute values of subexpressions first Then call value.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
1 Review of applets & Computer Graphis GUILecture 6 Review of Applets & Compute Graphics GUI Overview  Introduction to Graphics. Applets: a quick review.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
Handling Errors with Exception (in Java) Project 10 CSC 420.
Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Fonts And Image. Fonts To display text, we choose a font. Recall that we are dealing with pixels in graphics programming. To choose a font, we need to.
GUI Tutorial Images. Useful Info – not on final exam.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Threads and Multimedia Animation, Images, Sound. Animation nAnimation, displaying a sequence of frames to create the illusion of motion, is a typical.
Graphics and Multimedia Part #2
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
1 Learning objectives By the end of this chapter you should be able to:  explain how concurrency is achieved by means of time-slicing;  distinguish between.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Review of Graphics in Java,
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Java Programming Working with Sound and Images. Topics Learn about the paint() and repaint() methods Learn about paintComponent() method Use the drawString()
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812)
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Chapter 5 Introduction to Defining Classes
Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
Error Handling Tonga Institute of Higher Education.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
1 CSE 331 Design Patterns 2: Prototype, Factory slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Java 2D Image Manipulation A Brief Overview Ziv Yaniv.
Exception Handling. VB.NET has an inbuilt class that deals with errors. The Class is called Exception. When an exception error is found, an Exception.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Image mapping in HTML Please use the speaker notes for additional information.
Task 1 and Task 2. Variables in Java Programs Variables start with lower case letter Variables are descriptive of what they store Variables are one word.
Slide design: Dr. Mark L. Hornick
Java Applet.
Java Programming: Guided Learning with Early Objects
Mobile Computing With Android ACST 4550 Bitmaps, Fonts and Gestures
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Presentation transcript:

23-Jun-15 Images

Drawing images Java can display.gif,.jpg (or.jpeg ), and.png images These are the only kinds it can display Displaying them is (relatively) easy: Get the Graphics of the panel you want to display them in Call this method of your Graphics object: boolean drawImage(Image img, int x, int y, ImageObserver observer) where: img is the image x, y are the coordinates of the upper left-hand corner observer – the enclosing JFrame works well for this argument Example: myPanel.getGraphics().drawImage(myImage, 0, 0, this);

Why an ImageObserver ? boolean drawImage(Image img, int x, int y, ImageObserver observer) This method “Draws as much of the specified image as is currently available.” It returns true if the entire image is available It notifies the ImageObserver if more has become available In general, it would be nice if the images were loaded before attempting to display them In particular, attempting to display a null image is an error

Loading images This is ridiculously difficult. Here goes... Get a Toolkit that can load the image Toolkit toolkit = Toolkit.getDefaultToolkit(); Get a MediaTracker that can watch images being loaded MediaTracker tracker = new MediaTracker(owner); A JFrame makes a perfectly good owner Tell the toolkit that you want to load the image Image image = toolkit.getImage(fileName); Tell the MediaTracker to track the image tracker.addImage(image, 0); A MediaTracker can track any number of images at once Tell the MediaTracker to start loading the images (bet you thought getImage did this!) and wait for them to finish loading tracker.waitForAll(); Finally, handle the Exception s that might occur

The End