Georgia Institute of Technology Making Text for the Web part 2 Barb Ericson Georgia Institute of Technology March 2006.

Slides:



Advertisements
Similar presentations
Lecture 15: I/O and Parsing
Advertisements

Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
Files from Ch4. File Input and Output  Reentering data all the time could get tedious for the user.  The data can be saved to a file. Files can be input.
James Tam Simple file handling in Java Simple File Input And Output Types of Java files Simple file output in Java Simple file input in Java.
1 CS100J 12 April 2007 Applications and Applets Read Chapter 16 of the text I never let my schooling interfere with my education. Mark Twain Learning makes.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 1 Files.
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
Georgia Institute of Technology Making Text for the Web part 4 Barb Ericson Georgia Institute of Technology March 2006.
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology Creating and Modifying Text part 4 Barb Ericson Georgia Institute of Technology Oct 2005.
Georgia Institute of Technology Making Text for the Web part 5 Barb Ericson Georgia Institute of Technology March 2006.
1 Chapter 11 – Files and Streams 1 Introduction What are files? –Long-term storage of large amounts of data –Persistent data exists after termination of.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
1 HTML John Sum Institute of Technology Management National Chung Hsing University.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
OOP with Java, David J. Barnes Input-Output1 A complex issue in programming language design. The interface to the outside world. –Differences must be accommodated.
Georgia Institute of Technology Movies part 2 Barb Ericson Georgia Institute of Technology April 2006.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
20 Oct - Overview Homework #1 Group-Id rule Notes on Java text file input/output –Scanner class –Printf (like C)
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
LEARNING HTML PowerPoint #1 Cyrus Saadat, Webmaster.
File IO Basics By Dan Fleck Coming up: Data Streams.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
CPSC1301 Computer Science 1 Chapter 12 Creating and Modifying Text part 4.
Georgia Institute of Technology Making Text for the Web Barb Ericson Georgia Institute of Technology March 2006.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Georgia Institute of Technology Movies Barb Ericson Georgia Institute of Technology April 2006.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
CIS Intro to JAVA Lecture Notes Set 6 2-June-05.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
CreatingClasses-SlideShow-part41 Creating Classes part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Movies part 4 Barb Ericson Georgia Institute of Technology April 2006.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Winter 2006CISC121 - Prof. McLeod1 Stuff We had better discuss a midterm date… –27 Feb. to 3 March or –6 to 10 March.
Using Data Files Eric Roberts CS 106A February 22, 2016.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Georgia Institute of Technology Creating and Modifying Text Barb Ericson Georgia Institute of Technology June 2005.
For Friday Finish reading chapter 9 WebCT quiz 17.
1 Input-Output A complex issue in programming language design. The interface to the outside world. –Differences must be accommodated as transparently as.
Georgia Institute of Technology Making Text for the Web part 3 Barb Ericson Georgia Institute of Technology March 2006.
OO Design and Programming II I/O: Reading and Writing
Lecture 5 Text File I/O; Parsing.
Reading from a file and Writing to a file
Creating and Modifying Text part 2
Manipulating Pictures, Arrays, and Loops part 2
Unit 6 Working with files. Unit 6 Working with files.
Workshop for Programming And Systems Management Teachers
Workshop for Programming And Systems Management Teachers
Manipulating Pictures, Arrays, and Loops
Workshop for Programming And Systems Management Teachers
HTML Structure.
Making Text for the Web part 6
EEC 484/584 Computer Networks
Barb Ericson Georgia Institute of Technology May 2006
Lecture 6 Text File I/O Parsing Text CS2012.
Presentation transcript:

Georgia Institute of Technology Making Text for the Web part 2 Barb Ericson Georgia Institute of Technology March 2006

Georgia Institute of Technology Writing HTML Now that you know basic HTML You can write a program that outputs an HTML page Use a BufferedWriter and FileWriter to write out the file –From java.io Use the write method to output the HTML Use the newLine method to force a new line

Georgia Institute of Technology Writing a Program to Generate HTML public class WebPageWriter { /** * Method to write an example web (HTML) page fileName the file to write to */ public void writeExamplePage(String fileName) { // try the following try { // open a file for writing BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); // start the html page writer.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD " + "HTML 4.01 Transition//EN\""); writer.newLine(); writer.write("\" writer.newLine(); writer.write(" "); writer.newLine(); // write out the header writer.write(" A simple web page" + " "); writer.newLine(); // write out the body writer.write(" "); writer.newLine(); writer.write(" A Simple Heading "); writer.newLine(); writer.write(" Some simple text "); writer.newLine(); writer.write(" "); writer.newLine(); // end the page writer.write(" "); // close the writer writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }

Georgia Institute of Technology Write Example Page Test this method –Compile the class –Execute the method –Check the resulting HTML page But why would we want to do this? –Why write a program to output an HTML page that we could write by hand?

Georgia Institute of Technology Writing Programs that Output HTML Write programs –To have reusable parts –To communicate process –To allow for tailoring So breakup the writing of an HTML page –Into reusable parts that allow for tailoring –Break tasks into subtasks (procedural abstraction) Create helper methods –Methods that help another method accomplish a task –These are usually private methods

Georgia Institute of Technology Method to Start an HTML Page /** * Method to write the doctype and html tags writer the writer to use IOException */ private void writeStart(BufferedWriter writer) throws IOException { // write the document type writer.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD " + "HTML 4.01 Transition//EN\""); writer.newLine(); writer.write("\" writer.newLine(); // start the html page writer.write(" "); writer.newLine(); }

Georgia Institute of Technology Write out the Heading and Title /** * Method to write the title out writer the writer to use title the title to use IOException */ private void writeHead(BufferedWriter writer, String title) throws IOException { writer.write(" " + title + " "); writer.newLine(); }

Georgia Institute of Technology Start the Body /** * Method to write the body of the page writer the writer to use body the body to write IOException */ private void writeBody(BufferedWriter writer, String body) throws IOException { writer.write(" " + body + " "); writer.newLine(); }

Georgia Institute of Technology Finish the Page /** * Method to finish the html page writer the writer to use IOException */ private void writeEnd(BufferedWriter writer) throws IOException { writer.newLine(); writer.write(" "); writer.newLine(); writer.write(" "); }

Georgia Institute of Technology Method to Write a Homepage /** * Method for writing a homepage for the passed * name name the person's name interests a list of the person's interests */ public void writeHomepageV2(String name, String interests) { // try the following try { // open a file for writing BufferedWriter writer = new BufferedWriter(new FileWriter(name + ".html")); // write the start writeStart(writer); // write the header writeHead(writer,name + "'s Homepage"); // write the body writeBody(writer," Welcome to " + name + "'s Homepage " + " I am interested in " + interests); // end the page writeEnd(writer); // close the writer writer.close(); } catch (Exception ex) { ex.printStackTrace(); }

Georgia Institute of Technology How this Works Methods can call other methods –If the other methods aren't needed outside the class make them private These are called helper methods When you call –writeHomepageV2("Barb Ericson","horseback riding, reading, and genealogy"); –This method will call the helper methods as it encounters them

Georgia Institute of Technology Create a Web page from a Directory Get all the image files in a directory –Ending with.jpg –And write out an html page that has thumbnails (smaller versions) of the images Use the helper methods –To write out the basics of the HTML page Get the line separator for the current system –And use that to add a new line String endOfLine = System.getProperty("line.separator");

Georgia Institute of Technology Create Image Page public void createImagePage(String directory) { String name = null; String body = ""; String endOfLine = System.getProperty("line.separator"); // try the following try { // create the File object File dir = new File(directory); // get the full path name of the directory String pathName = directory + dir.getName() + ".html"; BufferedWriter writer = new BufferedWriter(new FileWriter(pathName)); // write the start writeStart(writer); // write the head writeHead(writer,"Thumbnails from " + directory); // get the array of items in the directory String[] items = dir.list(); // loop through the array for (int i = 0; i < items.length; i++) { name = items[i]; if (name.indexOf(".jpg") >= 0) { body = body + " Filename: " + name + " " + endOfLine; } // write the body writeBody(writer,body); // write the end writeEnd(writer); // close the writer writer.close(); } catch (Exception ex) { ex.printStackTrace(); }

Georgia Institute of Technology Main for Testing Create Image Page public static void main(String[] args) { WebPageWriter writer = new WebPageWriter(); String dir = "c:/intro-prog-java/mediasources/"; writer.createImagePage(dir); }

Georgia Institute of Technology Exercise Add a createImageTablePage method that puts 4 images in the first row of a table on a web page and then puts the file names in the row below the images Add a createSoundPage that lists all the sound files in the mediasources directory in a bulleted list –Use a hyperlink around the name of the sound file and it will play when you click on it soundFile.sav

Georgia Institute of Technology Summary You can use Java programs to create HTML You can break up a long public method into smaller private methods –Procedural abstraction HTML pages can be generated from information in a directory –Like all the pictures or sound files