Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn.

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interfaces (Part IV)
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Deitel Ch 11-part 1 Java GUIs 1 Java GUIs (Deitel, Chap 14-part1) Focus: Attaching GUI components + event handling  input dialog => only one value for.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Event Handling Events and Listeners Timers and Animation.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Chapter 121 Window Interfaces Using Swing Chapter 12.
© The McGraw-Hill Companies, 2006 Chapter 10 Graphics and event- driven programs.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Java Programming Chapter 10 Graphical User Interfaces.
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, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Field Trip # 21 Creating PDFs with Java By Keith Lynn.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Field Trip #19 Animations with Java By Keith Lynn.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
CS Lecture 00 Swing overview and introduction Lynda Thomas
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Lab 2: TCP /IP communication Southern Methodist University Bryan Rodriguez.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Alice in Action with Java Chapter 14 Events and GUIs.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
University of Limerick1 Software Architecture Java Layout Managers.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Field Trip #28 Securing a VNC Connection with Java By Keith Lynn.
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.
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.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Test Postmortem Dennis Burford
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUIs & Event-Driven Programming Chapter 11 Review.
Field Trip #29 Creating an Event Calendar with Java By Keith Lynn.
© Copyright by Pearson Education, Inc. All Rights Reserved. Appendix I GUI Components and Event Handling Android How to Program, 3/e.
Graphical User Interfaces
CompSci 230 S Programming Techniques
Appendix I GUI Components and Event Handling
A First Look at GUI Applications
CHAPTER 7 & 8 REVIEW QUESTIONS
Graphical User Interface (pronounced "gooey")
Graphical user interface with Swing by jose maria gonzalez pinto
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Graphical User Interface
Presentation transcript:

Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn

JPanel A JPanel is a lightweight component that can be placed inside other containers It can have its own layout If we want to draw Graphics on the panel, we override the paintComponent method

JFrame A JPanel can be placed inside a Jframe A Jframe is a top-level container in Java We can set the layout of the Jframe to FlowLayout to have components laid out in a row If we want to specify the size of a component, we use the method setPreferredSize which accepts a Dimension object

JButton A Jbutton is a graphical component that can be added to a container The Jbutton contains a label which can either be text of an image If we want to detect and act on the button click, then we must attach an ActionListener to the Jbutton ActionListener is an interface which contains the method actionPerformed which accepts an ActionEvent object

Events An event like a button click can be detected When we have an ActionListener attached to a Jbutton and the button is clicked, actionPerformed is called We can find the source of the event with getSource() and we can find the action command of the source with getActionCommand() Unless we specify otherwise, the action command of a Jbutton is its label

URL URL is found in the java.net package We can use it to open a file on the web as long as we can access it in a browser When we create a URL, we need to make sure that we deal with the potential of a MalformedURLException We can open the stream of the URL with the method openStream

Streams A stream is a continuous flow When we connect to a URL and open its stream, then we create a stream of bytes We can read all of the bytes of the URL As long as the remote server is setup to properly send the bytes of the file and read all of the bytes, then we can save the file on our hard drive and open it

Arrays We can make use of arrays in downloading the information To make the reading efficient, we attach a BufferedInputStream to the stream of the URL BufferedInputStream allows us to read in large chunks of the URL at once For each chunk of the URL we read, we accumulate these in an array of bytes Once we have read all bytes of the URL, then we can save the array

FileOutputStream To save the array of bytes, we can create a FileOutputStream which will open a byte connection to a file For efficient writing, we attach a BufferedOutputStream to the FileOutputStream We write the entire array to the BufferedOutputStream We make sure we close the stream

Downloading an image or sound In order to download an image or sound, locate one on the web Then place the URL in the JtextField When you click the download button, the file will be downloaded Since we are downloading the bytes of the file, we will get an exact copy