Field Trip # 21 Creating PDFs with Java By Keith Lynn.

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
Corresponds with Chapter 12
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Java Programming Chapter 10 Graphical User Interfaces.
Applets Java API.
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 Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Field Trip #19 Animations with Java By Keith Lynn.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
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.
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.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
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.
Applets Yong Choi School of Business CSU, Bakersfield.
University of Limerick1 Software Architecture Java Layout Managers.
Field Trip #28 Securing a VNC Connection with Java By Keith Lynn.
Field Trip #22 Creating an Excel Spreadsheet with Java By Keith Lynn.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
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)
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Review_6 AWT, Swing, ActionListener, and Graphics.
Computer Science 209 GUIs Model/View/Controller Layouts.
Field Trip #27 Using Java to Download Images and Sounds By Keith Lynn.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
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.
Graphical User Interfaces Tonga Institute of Higher Education.
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.
Graphical User Interface (GUI)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Field Trip #34 Creating and Reading Zip Files in Java By Keith Lynn.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Field Trip #29 Creating an Event Calendar with Java By Keith Lynn.
Graphical User Interfaces
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Timer class and inner classes
Graphical User Interface
Presentation transcript:

Field Trip # 21 Creating PDFs with Java By Keith Lynn

Java Frames A JFrame is a top-level container It can run in a stand alone program It can contain independent panels The JFrame has a title

LayoutManager LayoutManagers define how components are placed on a container There are predefined layout managers, we can use. FlowLayout (components arranged linearly), GridLayout (components arranged in a grid), GridBagLayout (we can assign weights to components so they can take up more than one row or column)

JButton A JButton is a component that we can place on a JFrame It is a push button We can place a label in the button A JButton has a margin. If the label won't display, we can obtain the insets of the button and change the margin

Handling Events In order to handle events like button clicks, we attach a listener to the button We implement the ActionListener interface which contains the method actionPerformed If the listener is attached properly to the button, then when the button is clicked, actionPerformed is called

Importing Packages Packages are a way of arranging similar classes In order to use a package, we import it We can import a single class or we can import a group of classes using the wildcard (*) Note that import is not recursive If we use a wildcard to import classes, it will not import subpackages

iText Itext is a package written by Bruno Lowagie It allows us to directly create a PDF document It also allows us to also read PDF documents We can place text on the PDF We can also place images We can load PDF forms and fill them in

Creating a Basic PDF Document We begin by creating a Document object We next create a FileOutputStream object and use the FileOutputStream to create a PdfWriter Before we put anything in the Document, we open it After we have created the Document, we close it It is necessary to close the Document when we are done

Things we can do with a PDF Document Drawing a graph Drawing an image Drawing a Table Drawing Graphics Drawing Chart There are other things that can be done with a PdfContentByte, but these are the ones we will consider

Drawing a Graph To draw the graph, we will consider points on the coordinate system where (0,0) is the origin and translate them to a system where the original is at the middle of the PDF (420,300) We compute the value of the function and translate it to this system Each time we place a new point on the graph, we use the method lineTo Once we have moved to all points, we call the method stroke

The graph

Drawing an Image We will create something similar to the graph We will compute the Mandlebrot set which is a special fractal After the set has been computed, we create a BufferedImage We then use then add the image to the document with the method addImage

The image

Drawing a Table We can easily creating columnar text by using a PdfPTable We specify the number of columns in the table Then we one by one place the elements in the table One interesting use of the PdfPTable is to connect to a Wikipedia site and download information about Presidents and Vice Presidents and put them in a table

The table

Downloading information We can connect to a URL with the URL object We can openStream on it We can then read from it using a FileInputStream We can wrap the FileInputStream in a Scanner and read the whole contents using the method useDelimiter(“\\Z”)

Drawing Graphics We can also draw graphics on a PDF like we can a Java program We can obtain a reference to a Graphics object by calling the method createGraphics and specifying a width and height This gives us a Graphics2D object We can then use any draw method we would use in the paint method of an applet

The graphics

Creating a Chart Another interesting thing we can do in a PDF is create a chart There is a special third party library called JfreeChart Using JFreeChart, we can easily create bar charts and pie charts In order to draw the bar and pie charts we create a Graphics2D object and draw on that object

The Bar Chart

The Pie Chart