Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Advertisements

JFrame JComponent JFrame JComponent JFrame JComponent.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Introduction to Input and Output. Layers (or Tiers) of an Application  Software in the real world normally takes the form of a number of independent.
Event Handling Events and Listeners Timers and Animation.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 : Event-Driven Programming and GUI Objects.
Chapter 7 Event-Driven Programming and Basic GUI Objects.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Io package as Java’s basic I/O system continue’d.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Field Trip #26 Create a Find a Word Puzzle in Java By Keith Lynn.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Operating Systems TexPREP Summer Camp Computer Science.
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Field Trip #19 Animations with Java By Keith Lynn.
Field Trip #31 CrossWord Puzzle By Keith Lynn. JApplet A JApplet is a top-level container in Java We will use the JApplet to contain two Jpanels The first.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Lecture 20 April 13, Review for Exam All Exercises and Sample Code from Lectures Object Based Programming Object Oriented Programming String and.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Field Trip #28 Securing a VNC Connection with Java By Keith Lynn.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Object Oriented Programming.  Interface  Event Handling.
Field Trip #25 Creating a Client/Server By Keith Lynn.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
Field Trip #29 Creating an Event Calendar with Java By Keith Lynn.
A Quick Java Swing Tutorial
GUI Programming using Java - Event Handling
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
Graphical User Interfaces
Appendix I GUI Components and Event Handling
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
Creation of an Android App By Keith Lynn
Java Programming: From Problem Analysis to Program Design,
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Introduction to Event Handling
Zip Archives and ColdFusion
A Quick Java Swing Tutorial
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn

java.util.zip The java.util.zip package contains classes that allow us to both read and write zip files A zip file is a file which supports lossless data compression It was very essential when hard drives were small Now, not only does the zip file allow us to save space, but also allows us to organize files

ZipEntry In order to create a zip file, we create one or more ZipEntrys When we create a ZipEntry, we typically specify the name of the next file These are the names we see if we look at the contents of the file The ZipEntry does not contain the contents of the file

Loading the contents of a file We can think of a file as a collection of bytes Even if the file contains text, we can still think of it as bytes In order to maintain the integrity of the file, we want to make sure we preserve the bytes of the file In order to do this, we can make use of a FileInputStream

Streams A stream can be thought of a flow of elements When we want to read the bytes of a file, we can use a flow of bytes The FileInputStream will allow us to make a connection to a file to read its bytes, and the BufferedInputStream allows us to read efficiently from it The read method in BufferedInputStream will allow us to read a certain amount of bytes at a time from the file until we read them all

ZipOutputStream When we want to create the zip file, we will first create an instance of a FileOutputStream This will create an output stream that will let us write bytes to a file In order to write a zip file, we then create a ZipOutputStream using that basic connection When we write to the ZipOutputStream, it will properly place ZipEntries and file content in the zip file When we are done, we want to make sure we close the ZipOutputStream

ZipInputStream To read in a zip file, we first create an instance of a FileInputStream and attach it to the file This allows us to read bytes from the file We then create a ZipInputStream using the FileInputStream This file allows us to properly retrieve ZipEntries and file contents

JFrame To facilitate creating and reading zip files, we will create an instance of a JFrame The JFrame is a graphical interface The JFrame allows us to place a menu bar on the screen We will place menus that allow the user to specify what directory to place in the zip file and what zip file to read

JTextArea The JTextArea is a graphical component that allows us to place a large amount of text on the screen We will typically place the JTextArea in a JScrollPane so that if there is more text that we want to place in the text area, scrollbars will appear Depending on the layout manager used in the JFrame, we will typically need to specify the preferred size of the JScrollPane

Events In order to detect an event, we must create an event listener There is a package java.awt.event that contains interfaces we can use to detect and act on events An interface is a special Java source file that contains a list of methods to be implemented by the user When a user implements the interface, then it becomes the listener

Detecting and acting on selecting menus To detect when a user selects a menu item, we attach an ActionListener to the menu item The ActionListener interface contains the method actionPerformed which accepts an ActionEvent parameter We can detect the source of an event with the method getSource() and the label of the source with the method getActionCommand()