ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 7 JAVA Cup.

Slides:



Advertisements
Similar presentations
The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
Advertisements

Chapter - 12 File and Streams (continued) This chapter includes -  DataOutputStream  DataInputStream  Object Serialization  Serializing Objects 
ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 6 JAVA Cup.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Chapter 7 Inheritance, Polymorphism, and Scope.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
Chapter 91 Streams and File I/O Chapter 9. 2 Reminders Project 6 released: due Nov 10:30 pm Project 4 regrades due by midnight tonight Discussion.
ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems.
ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 9 JAVA Cup.
Lecture 241 CS110 Lecture 25 Tuesday, May 4, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last.
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
Io package as Java’s basic I/O system continue’d.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 2 How to Compile and Execute a Simple Program.
More on Inheritance Dr. Andrew Wallace PhD BEng(hons) EurIng
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Stream: an object that either delivers data to its destination (screen, file, etc.) or that takes data from a source (keyboard, file, etc.) –it acts as.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Object Persistence and Object serialization CSNB534 Asma Shakil.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
CS Lecture 00 Swing overview and introduction Lynda Thomas
Lecture 20 April 13, Review for Exam All Exercises and Sample Code from Lectures Object Based Programming Object Oriented Programming String and.
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Lecture 5: Java Introduction Advanced Programming Techniques Summer 2003 Lecture slides modified from B. Char.
Basics of GUI Programming Chapter 11 and Chapter 22.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Advanced Java Class Events. change in state initiated by system or user java.util.EventObject java.awt.event java.swing.event.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
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.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Files and Serialization. Files Used to transfer data to and from secondary storage.
Sep 181 Example Program DemoTranslateEnglishGUI.java.
Java Programming: Advanced Topics 1 Input/Output and Serialization.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
CSE 205 Exam 2 Review By Cheri Thompson and Katherine Kincade.
Lecture 6 Object Oriented Programming Using Java By Rashid Ahmad Department of Computer Science University of Peshawar.
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
CSC 205 Programming II Lecture 5 AWT - I.
CHAPTER Reacting to the user.
OBJECT ORIENTED PROGRAMMING II LECTURE 22 GEORGE KOUTSOGIANNAKIS
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 7 JAVA Cup 7: It’s all in the Packaging

17 October 2002Web Technology for IE2 Handouts Lecture 7 slides READ Winston & Narasimhan : –Chapters (pp )

17 October 2002Web Technology for IE3 JAVA Cup 7 Characters and Strings –Codestrings and delimiters How to Read/Write Objects How to Modularize Programs Creating a Window

17 October 2002Web Technology for IE4 Specifying Delimiters You can use codestrings to specify interesting information in textfile

17 October 2002Web Technology for IE5 Specifying Delimiters To advise the tokens tokenizer to use double quotation marks to delimit strings: –tokens.quoteChar((int) ‘”’) To tell the tokenizer to recognize carriage returns: –tokens.eolIsSignificant(true);

17 October 2002Web Technology for IE6 Working with O/p File Streams To connect to output file –FileOutputStream stream = new FileOutputStream(“output.data”); To write more than 1-byte-at-a-time –PrintWriter writer = new PrintWriter(stream); It’s good to flush out buffered characters –writer.flush() Close the file –stream.close()

17 October 2002Web Technology for IE7 Reading / Writing Objects Serialized input-output operations –.writeObject( ) –.readObject() Indicate intentions to use operations by –implements Serializable –throws IOException, ClassNotFoundException Each instance must belong a class that implements the Serializable Interface

17 October 2002Web Technology for IE8 Review streamreaderbuffer streamwriter streamreadertokens

17 October 2002Web Technology for IE9 Reading Objects from File FileInputStream fileInputStream = new FileInputStream(“in.data”); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); Vector = (Vector) objectInputStream.readObject();

17 October 2002Web Technology for IE10 To Write Objects to File FileOutputStream fileOutputStream = new FileOutputStream(“out.data”); ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject( ); objectOutputStream.close();

17 October 2002Web Technology for IE11 Modularing Your Program Compilation Units Packages Setting CLASSPATH Calling Methods from a Module Access to Var/Methods in Package

17 October 2002Web Technology for IE12 Compilation Units Define all classes in same file Only one class can be public Only one class is universally accessible Convention: each class has its own compilation unit

17 October 2002Web Technology for IE13 Packages Use single-class compilation units Indicate module using package statement at beginning of each c.u –package onto.java.entertainment; Convention: package names consist of components separated by dots

17 October 2002Web Technology for IE14 CLASSPATH Package names correspond to paths –package onto.java.entertainment; –Files stores in./onto/java Setting the path –setenv CLASSPATH : :. –setenv CLASSPATH= ; ;. UNIX PC

17 October 2002Web Technology for IE15 Using Methods from a Package First import package –import onto.java.entertainment.* –Auxiliaries.readMovieFile( “input.data” ) –(( Movie ) vectorElement).rating() Or, refer to entire name –onto.java.entertainment.Auxiliaries.readMovieFile ( “input.data” ) –(( onto.java.entertainment.Movie ) vectorElement).rating()

17 October 2002Web Technology for IE16 Access to Variables/Methods private : –available only to methods inside own class protected : –available to methods in same class, c.u. or package, subclasses No keyword : –available only to c.u. or package

17 October 2002Web Technology for IE17 How to Create Windows Nomenclature Intro to Swing classes Hierarchy of Swing classes Listener Classes Window Creation Pattern

17 October 2002Web Technology for IE18 Nomenclature GUI ( pronounced goo-ey ) : –Graphical User Interface Components : –class instances that have a graphical representation Containers : –components that allow nesting of other containers inside their boundaries Window : –a container’s graphical representation

17 October 2002Web Technology for IE19 Introduction to Swing (J) Classes API = Application Programmer’s Interface The AWT Package: java.awt.* –AWT = Abstract Window Toolkit –contains Component, Container classes The Swing Package: java.swing.* –contains JFrame, JApplet, JComponent, JPanel classes Try to restrict display work to Swing classes

17 October 2002Web Technology for IE20 Hierarchy of Swing Classes

17 October 2002Web Technology for IE21 Example: A Window import javax.swing.*; public class Demonstrate { public static void main (String argv []) { JFrame frame = new JFrame (“ I am a window, square and proud ”); frame.setSize(200,200); frame.show(); }

17 October 2002Web Technology for IE22 Listener Classes Event as a state change –Mouse clicks and key presses –Variable-value changes Event as instance of EventObject class –Describes state change Java deals with events through Listener Classes Listener classes are defined by –Extending existing listener classes –Implementing listener interfaces

17 October 2002Web Technology for IE23 When mouse clicks: –a WindowEvent instance is created –the windowClosing method is called with connected listener as target and WindowEvent instance as arg Example: Link listener to frame

17 October 2002Web Technology for IE24 Adapter Classes Adapter classes implement all interface-required methods as do- nothing methods. You can define shadowing methods in your subclass for whatever subset of methods you need

17 October 2002Web Technology for IE25 Nesting Class Definitions Advantage of nesting classes: –Method definition (windowClosing) appears in proximity to window definition –Can reuse names of private classes such as LocalWindowListener

17 October 2002Web Technology for IE26 Window Creation Pattern Define a subclass of JFrame class Main method calls constructor Constructor: –assigns title, size, and displays a window –creates required class instances –connects class instances