CASE STUDY: Applet Development with GUI and Client-side File Input Arkadiusz Edward Komenda.

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

George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 3.
The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 1 Introducing Java.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Applets The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Developing User Interfaces (DUI) Chris North cs3724: HCI.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets Java API.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application Introducing Visual Web Developer 2008 Express and the.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
JAVA SECURITY BASIC NETWORKING MULTITHREATING Deniz HASTORUN
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
JavaScript - A Web Script Language Fred Durao
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.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
1 Class 6. 2 Objectives Objectives Identify, declare, and use primitive data types Use the System class to create data streams Use the Scanner class of.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Creating a Java Application and Applet
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Applications Active Web Documents Active Web Documents.
Introduction to Programming and Visual Basic
A First Look at GUI Applications
Java Programming: From Problem Analysis to Program Design,
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
30 Java Applets.
CIS16 Application Development Programming with Visual Basic
Java Applets.
Presentation transcript:

CASE STUDY: Applet Development with GUI and Client-side File Input Arkadiusz Edward Komenda

Professor Blank’s Introduction I asked Mr. Komenda to write this case study of problem 4.2 in the text because he did an effective job of solving several problems that are required to create an applet that reads files, when all the other students in the class had to write an application instead of an applet. He had to solve several problems before the related material was covered in the text.

Certificates and Files on Client not recommended! A signed jar file is not the best solution to this problem. It is necessary to access files on the client. But the server is a better place to keep files. A separate tutorial is provided to show you how to access files on the server using the Eclipse IDE. However, this tutorial is a great introduction to several of the challenges involved in Java programming. It can give you a head start, as well as a reference when the topics are covered.

Problems to be solved: This early in the course (Chapter 4), most students cannot use: –GUI Panels –File Dialog Boxes –Exception Handling – File I/O –Java Jar Files –Certificates

Special notes It would have been more appropriate in this case to put the file of numbers to be counted and averaged on the AFS server in the same directory from which the applet is loaded instead of on the user’s disk. Then the certificate should not be necessary. Also, this uses a self-published certificate instead of one from a certificate authority, so it requires the user to trust the developer of the certificate.

Problem Statement Write a Java applet to calculate the average of a list of integers and their count. The input data is stored in a text file, in which each line contains a single integer. The input file is chosen via Open File Windows-like Dialog box. The average and count (number of integers in a file) are displayed within the applet. Provide for error checking of the file name, i.e. the program should display a meaningful message when the input file name is incorrect, and it should ignore any lines in the input file that are other than a single integer.

Application or Applet One of the key differences between an application and an applet is start-up. Every application needs a main method, which tells the program where to start. Applets cannot have a main method. Every applet needs at least one of these methods: init, start, or paint. The browser uses init to notify the applet that it has been loaded and start to tell the applet that it can begin executing. Anything displayed in the applet must use a paint method.

Outline Graphical User Interface (GUI) Event Handling File Input Processing (average and count calculation) Exception Handling JAR and Signing Applet

Class Definition Declare class AverageCount Extend it as an Applet Event Handling Remember to import packages supporting applets and Abstract Window Toolkit (AWT) for GUI 1 2

Graphical User Interface (GUI) Our Applet GUI consists of Panels Panel for our purpose can be imagined as a rectangular plane (container) where it is possible to place Button s, Label s, TextField s, Checkbox es, etc.

Panels, Buttons, Labels (1) Three panels are declared: –mainPanel – holds three Label s with information and instructions to the user about the program ( mainLabel, mainLabel2, mainLabel3 ) –buttonPanel – holds a Button that will activate Open File Dialog box and after selection of an input file the applet will proceed with calculation of the average ( openButton ) –displayPanel – holds two Label s which will display the results ( resultLabel, resultLabel2 )

Panels, Buttons, Labels (2) buttonPanel displayPanel mainPanel openButton mainLabel mainLabel2 mainLabel3 resultLabel resultLabel2

Panels, Buttons, Labels (3)

Event Handling (1) When user clicks on Open Button, the applet opens a dialog box to select an input file class AverageCount implements ActionListener interface which contains one method actionPerformed Remember to import java.awt.event.* package 2 1

Event Handling (2) openButton is tied to ActionListener actionPerformed method defines what actions should be taken once Open Button is clicked

Event Handling – Our Applet

File Input – Dialog Box Define new Frame to hold Open File Dialog box Create Open File Dialog box ( FileDialog ) in the Frame Once the user clicks on Open Button, then actionPerformed method calles doOpen() to display ( setVisible ) Open File Dialog box 1 2 3

File Input – The Applet

File Input – Access Define FileReader and BufferedReader to open the selected file and read data from it File name and file path are stored in File type object and are passed to the FileReader Actual reading of data is performed by BufferedReader via.readLine() method 1 2 3

Average Calculation and Count Calculation of the average of the integers and their count is straight forward 1 2

Exception Handling - Filename Error checking for the correctness of file name is handled by the use of try and catch statements When the file name is incorrect an appropriate message is displayed in resultLabels

Exception Handling - isOkInt Testing whether the read data from input file is an integer is done by isOkInt(String s) method, which is left for students to implement

JAR JAR is a packing utility similar to ZIP or TAR We can pack numerous files (.class,.gif, and others) into a single compressed archive file (filename.jar) When an HTML page loads an applet and encounters filename.jar file (specified between tags) it uploads the whole file in one connection, thus saving connection time To create a JAR file: jar cvf AverageCount.jar AverageCount.class

Signing Applet For an applet to access local files (stored on user’s local machine) the applet has to be in the form of a JAR file (AverageCount.jar) which has your digital certificated attached to it. In short, a JAR file has to be signed Before signing a JAR file, you must make your own digital certificate –At the prompt type: keytool -genkey -keyalg rsa -alias mykey keytool -export -alias yourkey -file mycertificate.crt mycertificate.crt is a file with your digital certificate Now to sign AverageCount.jar file –jarsigner AverageCount.jar mykey

Applet Deployment Place AverageCount.jar (after signing it) on the HTTP server (AFS server at NJIT) In your.html file (e.g. AverageCount.html) include the following line in the place where you want your applet to appear on a web page <APPLET code="AverageCount.class" archive="AverageCount.jar" width=420 height=280>

Complete Program (1)

Complete Program (2)

Complete Program (3)

Complete Program (4)

Complete Program (5)

References Jia, Xiaoping. Object Oriented Software Development using Java- 2 nd edition, Adison Wesley