Download presentation
Presentation is loading. Please wait.
1
COMP 14: Files and Graphics for Applets June 19, 2000 Nick Vallidis
2
Announcements zP5 is due tomorrow
3
Homework zread Appendix J (p. 577-596) zP5 (due tomorrow) zP6 (due Friday)
4
Reading Text Files Almost Just Like User Input zSection 8.4 in textbook ypages 396 - 399 zWe 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 Files Almost Just Like User Input zFile 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 Files Visual J++ Demo zRead 10 integers from a file into an array zPrint the array
8
Reading Text Files In-Class Exercise zWrite code that displays the contents of a text file to the screen. zWe’ll write the actual code together
9
Graphics for applets zEverything you've done so far has been producing output as text. yjust a sequence of characters zNow we're going to talk about graphical output yeverything is made of colored dots
10
Introduction to Graphics zMost computer programs have graphical components zA picture or drawing must be digitized for storage on a computer zA picture is broken down into pixels (picture element), and each pixel is stored separately
11
Representing Color zA black and white picture can be stored using one bit per pixel (0 = white and 1 = black) zA color picture requires more information yevery color can be represented as a mixture of the three primary colors Red, Green, and Blue zIn Java, each color is represented by three numbers between 0 and 255 that are collectively called an RGB value
12
Coordinate Systems zEach pixel can be identified using a two- dimensional coordinate system zWhen 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) 112 40
13
Drawing a Line X Y 10 20 150 45 You specify a start point: (10, 20) You specify an end point: (150, 45) and
14
Drawing a Rectangle X Y You specify the upper left corner 50 20 100 40 and You specify the width and the height
15
Drawing an Oval X Y You specify a rectangle the oval fits in (what happens if the rectangle is a square?) 175 20 50 80 boundingrectangle
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.