1 / 15

COMP 14: Files and Graphics for Applets

COMP 14: Files and Graphics for Applets. June 19, 2000 Nick Vallidis. Announcements. P5 is due tomorrow. Homework. read Appendix J (p. 577-596) P5 (due tomorrow) P6 (due Friday). Reading Text Files Almost Just Like User Input. Section 8.4 in textbook pages 396 - 399 We know:

alicia
Télécharger la présentation

COMP 14: Files and Graphics for Applets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 14: Files and Graphics for Applets June 19, 2000 Nick Vallidis

  2. Announcements • P5 is due tomorrow

  3. Homework • read Appendix J (p. 577-596) • P5 (due tomorrow) • P6 (due Friday)

  4. Reading Text FilesAlmost Just Like User Input • Section 8.4 in textbook • pages 396 - 399 • We know: BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); String line = stdin.readLine();

  5. What does that really do? • Instantiates two objects! BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); is the same as… InputStreamReader strRdr = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(strRdr);

  6. Reading Text FilesAlmost Just Like User Input • File Input: BufferedReader filein = new BufferedReader (new FileReader (filename)); or FileReader fRdr = new FileReader(filename); BufferedReader filein = new BufferedReader (fRdr); filename is the name of the file to read String line = filein.readLine();

  7. Reading Text FilesVisual J++ Demo • Read 10 integers from a file into an array • Print the array

  8. Reading Text FilesIn-Class Exercise • Write code that displays the contents of a text file to the screen. • We’ll write the actual code together

  9. Graphics for applets • Everything you've done so far has been producing output as text. • just a sequence of characters • Now we're going to talk about graphical output • everything is made of colored dots

  10. Introduction to Graphics • Most computer programs have graphical components • A picture or drawing must be digitized for storage on a computer • A picture is broken down into pixels (picture element), and each pixel is stored separately

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

  12. (0, 0) X Y 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 upper left corner 112 40 (112, 40)

  13. X Y You specify a start point: (10, 20) and You specify an end point: (150, 45) Drawing a Line 10 150 20 45

  14. X 40 100 Y Drawing a Rectangle 50 20 You specify the upper left corner and You specify the width and the height

  15. X 80 50 Y Drawing an Oval 175 20 bounding rectangle You specify a rectangle the oval fits in (what happens if the rectangle is a square?)

More Related