Final Review (lectures 8-16) TA: Truman

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
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.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Event Handling Events and Listeners Timers and Animation.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
GUI. Swing Class Hierarchy Swing Components Swing Conatiners  JFrame – top-level window to store components.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
More on Creating GUIs in Java using Swing David Meredith Aalborg University.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
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,
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
– 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.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
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.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
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.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
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.
Review_6 AWT, Swing, ActionListener, and Graphics.
Basics of GUI Programming Chapter 11 and Chapter 22.
1 Chapter 16: Creating Windows. 2 Basics of GUI Programming How to create a Window. TryWindow.java You always need a JFrame component before creating.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Creating a GUI Class An example of class design using inheritance and interfaces.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
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)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
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.
Chapter 4 Interface Types and Polymorphism Part 2.
GUIs and Events Rick Mercer.
A First Look at GUI Applications
Advanced User Interfaces
Java GUI.
Graphical User Interface (pronounced "gooey")
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Events, Event Handlers, and Threads
FINAL EXAM Final Exam Wednesday, Dec 14: 8: :00 AM (Frny G140)
Graphical User Interface
FINAL EXAM Final Exam Tuesday, May 3: 1:00 - 3:00 PM (Phys 112)
Presentation transcript:

Final Review (lectures 8-16) TA: Truman

File File System –Directory, File, Permission (read, write, execute) –Permission: ls –l filename [in linux] Text vs Binary –Human readable, ascii encoding –Non-human readable..etc –Very imprecise definition though. Examples –myNotes.txt –mp3 –.exe –.class

File API a/io/File.htmlhttp://java.sun.com/j2se/1.5.0/docs/api/jav a/io/File.html createNewFile() Exists() isDirectory() …etc

File I/O Be able to read (input) and write (output) FileInputStream(String filename) FileOutputStream(String filename) Scanner class (input) –Scanner s = new Scanner(new FileInputStream(“input.txt”); –S.nextInt()…etc PrintWriter (output) –PrintWrite p = new PrintWriter(“output.txt”); –P.print()…etc –never throw I/O exceptions (use checkError()) –Print() vs println() –Buffering.

File I/O DataInputStream, DataOutputStream Random access file –Seek(long location)… Streams provide one-way access –Once it’s read, can’t go back Read/Write Objects –Needs to implement Serializable –Override writeObject(), readObject(). –ObjectInputStream, ObjectOutputStream Examples –ObjectInputStream in = new ObjectInputStream(new FileInputStream(“filename”); –In.readObject(); //cast to the right class

GUI vs Web page How to create GUI/Web pages? Basic idea: design the layout, then add stuff into it. Designing the layout in GUI is very similar to designing a web page For web pages, use HTML table For GUI, use LayoutManager

Swing Simplest example –JFrame j = new JFrame(“test”); j.setVisible(); JFrame vs JPanel –Both are containers – can contain other components –Create a window application (Jframe) –Add JPanel into it. –Every container can have its own layout JFrame –setVisible() –setDefaultCloseOperation() EXIT_ON_CLOSE HIDE_ON_CLOSE DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE –LayoutManager FlowLayout, BorderLayout, GridLayout –setMenuBar –Other components: JLabel, JTextfiedl, JCheckbox…etc

One example create a JFrame –setLayout(new BorderLayout()); GridLayout(), FlowLayout();…etc –setTitle, setSize, set…, add([component]); implement ActionListener –public actionPerformed(ActionEvent e) –e.getSource, e.getActionCommand()…etc addWindowListener([subclass of WindowAdapter]); setMenuBar(), JMenuBar, JMenu, JMenuItem JLabel, JButton, JTextField –setText JButton: setEnabled(true/false)

Interface What’s an interface? –It specifies what methods a class needs to have. –If your class implements an interface, need to implement all the methods Why need it? –Leads to better design –Less code change Can an interface “inherit” another interface? Can you define variables inside the interface? Note: you usually hear something like: “let’s agree on the interface…”

Listener What is it? –An object that satisfies the listener interface NO multiple inheritance, but can implement multiple interfaces ActionListener, WindowListener, MouseListener…etc An object can be a listener, meaning that it’s listening to some EVENTs, so that when the event occurs, the object can handle it. So what’s an event??

Event Low level –Mouse moved, pressed, –Key pressed…etc Semantic –User defined –Button pressed –Checkbox changed…etc You can even define your own events!

Inner class What’s the main difference between inner class and normal one? Local inner class –Defined in a method, local to that method only –Can ONLY access final local variables Anonymous class –Without providing a name –Pros: –Cons:

WindowAdapter Relationship to WindowListener? Why use window adapter? Pros & cons?

Draw stuff on JPanel paintComponent(Graphic g) When is this called? –Becomes visible –Resized –Repaint is called. Do you call it directly? –Call Repaint()

Design patterns Model View Controller Observer pattern

The Observer pattern defines an one-to- many dependency between a subject object and any number of observer objects so that when the subject object changes state, all its observer objects are notified and updated automatically. Subject == model

Java supports it! Model class extends Observable Observer class implements “Observer” interface When data changed, call –setChanged() –Notify()