GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.

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.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
1 Chapter 12 l Event-Driven Programming and GUIs l Swing Basics and a Simple Demo Program l Layout Managers l Buttons and Action Listeners l Container.
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.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Swing 4 th April 2008 CS 180 Department of Computer Science, Purdue University.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Java Swing. Introduction to Swing A GUI (graphical user interface) is a windowing system that interacts with the user The Java AWT (Abstract Window Toolkit)
Java Programming Chapter 10 Graphical User Interfaces.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
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.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
CS Lecture 01 Frames and Components and events Lynda Thomas
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
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.
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.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Layout Manager Summary
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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Event-Driven Programming and GUIs l Swing Basics and.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
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.
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.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
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.
Graphical User Interface (GUI)
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Graphical User Interfaces
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Creating Graphical User Interfaces
Window Interfaces Using Swing Objects Chapter 12
Steps to Creating a GUI Interface
Window Interfaces Using Swing Objects Chapter 12
GUI Layouts By: Leonard & Saif.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Graphical User Interface
Presentation transcript:

GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University

Announcement Project 5 due Wed, Mar. 11 at 10 pm. All questions on the class newsgroup. Do not wait till the last minute to start your project! Mid-term evaluation of this course.

Inheritance & Interface They will be focused later, but we can have a glance at their basic ideas. Inheritance models the is-a relationship.  Student is a Person.  Car is a Vehicle. Use extends to state an inheritance. Interface is a kind of protocol.  Human can Move. ( Move is an interface here)  Animal can Move. Use implements to implement an interface.

A Simple GUI Example This simple program produces a window and displays some text.  JFrame : to create a window  JLabel : to create a label  getContentPane().add() : add a component such as a label to the content pane of the window  setTitle() : set the title of the window  setSize() : set the size of the window  setVisible() : permits the programmer to specify when GUI objects should be displayed and when they should not

A Simple GUI Example public class MyWindow { public static void main(String args[]) { JFrame myWindow=new JFrame(); //create the window myWindow.setSize(300, 200); //set the title of the window myWindow.setTitle("this is a window"); //create the label JLabel myLabel=new JLabel("this is a label"); //add the label to the content pane of the window myWindow.getContentPane().add(myLabel); //set color of the content pane myWindow.getContentPane().setBackground(Color.CYAN); //make the window visible myWindow.setVisible(true); } A Frame This area is the content pane

Event Driven Programming An event is an object that represents an action.  Mouse clicking  Key pressing  Window closing  …

ActionListener & ActionAdapter … implements ActionListener … extends ActionAdapter They can both do the same thing, but what’s their differences? Keep that question till you learn inheritance and interface systematically. Anyway, remember the most useful method actionPerformed. What’s its argument?  ActionEvent (An event is also an object)

Layout Managers A layout manager arranges objects within a container. After a container has been created, you can set its layout manager using the setLayout method. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); FlowLayout : It simply lays out components in a single row, starting a new row if its container is not sufficiently wide.

Layout Managers BorderLayout : It places components in up to five areas: top, bottom, left, right, and center.  Default layout GridLayout : It simply arranges a bunch of components in a grid of rows and columns.

Nesting Panels How to create any kind of GUI as you wish?  The first choice is to draw a picture on the paper, calculate positions for all components and type in one by one.  Maybe we can use an IDE to drag some components onto the frame.  But what happens when the window is resized?  One decent solution is to use nested panels.

Nesting Panels DIY time – How to get these GUI styles?

Nesting Panels What about this?

Nesting Panels Very well! This? Whoops!! Why?

More Components Menus  JMenuBar  JMenu  JMenuItem Text  JTextField  JTextArea More…So, how can we remember all of them?!  Java API and the Internet

Quiz Do you think JPanel and JButton are similar components? If not, what’s the main difference between them? In this way, we can classify the components into two categories. Can you give two more examples, one similar to JPanel and the other similar to JButton ?