ITEC 109 Lecture 27 GUI Interaction. Review GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers –Flow / Box –Border / Grid.

Slides:



Advertisements
Similar presentations
Graphic User Interfaces Layout Managers Event Handling.
Advertisements

TCU CoSc Programming with Java Handling Events.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
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)
Event Handling Events and Listeners Timers and Animation.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Chapter 121 Window Interfaces Using Swing Chapter 12.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
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.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
JLabel, JTextField, JButton and JOptionPane
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
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.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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.
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.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
GUI Applications ButtonGroup and JRadioButton. Contents A.Problem: The Metric Converter Application B.Solution C.Exercise: Moving all calculations into.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
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.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
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.
Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.
Creating User Interfaces Event-Driven Programming.
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.
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)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
1 Lecture 8: User Interface Components with Swing.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Designing a User Interface with Swing Assignment Swing: Update code of an earlier program.
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:
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
A Quick Java Swing Tutorial
A First Look at GUI Applications
Chapter Topics 15.1 Graphical User Interfaces
Designing a User Interface with Swing
Graphical User Interface (pronounced "gooey")
Graphical user interface with Swing by jose maria gonzalez pinto
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Timer class and inner classes
Basic Elements of The GUI
Steps to Creating a GUI Interface
Chapter 12 GUI Basics.
Graphical User Interface
Presentation transcript:

ITEC 109 Lecture 27 GUI Interaction

Review GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers –Flow / Box –Border / Grid

GUI Interaction Objectives Add interactivity

GUI Interaction Gotcha Interactivity is required with GUIs printNow stops working when GUIs are introduced in your program… Labels are the only way to get info

GUI Interaction Need When you click on a button… How does your code get called –Push –Pull –Both

GUI Interaction Problem Python doesn’t know how to call your code Have to connect the two worlds When python was written vs when your program was written Censored

GUI Interaction Solution def buttonPressed(event): if (event.getSource() == aButton): printNow(“You pressed aButton”); aButton = swing.Jbutton() aButton.actionPerformed=buttonPressed You get a message from whatever got pressed

GUI Interaction Problem Need to access variable inside of function when it isn’t passed in… Solution: global Need god mode def myFunction(): global x x=4 x=3 myFunction() printNow(x)

GUI Interaction Structure Function that handles presses Function that handles presses Code that creates the GUI Code that links buttons with function Function that handles presses Function that handles presses GUI Components GUI Components Code that links buttons with function Allows

GUI Interaction Example import javax.swing as swing import java def pressed(event): global one global two global three if (event.getSource() == one): three.setText("+") elif (event.getSource() == two): three.setText("-") frame = swing.JFrame() frame.setSize(200,200) pane = swing.JPanel() frame.setTitle("Press demo") one = swing.JButton() one.setText("+") two = swing.JButton() two.setText("-") three = swing.JLabel() three.setText("Hmm....") pane.add(one) pane.add(two) pane.add(three) frame.setContentPane(pane) one.actionPerformed = pressed two.actionPerformed = pressed frame.show()

GUI Interaction Decisions One handler function or many Function that handles presses Function that handles presses Button1 Button2 Button3 Button4 Press1 Button1 Press2 Button2 Press3 Button3

GUI Interaction Design Starts with a conversation Paper prototypes Refined into Java components Skeleton system Fully functional system

GUI Interaction Warning GUIs add a lot of complexity to projects 5000 LOC just for a GUI is rather common Separate part, but it takes on a life of its own

GUI Interaction Tools What all can you use? –Buttons –Text –Text entry What are other GUI elements?

GUI Interaction Popups Easy to use, nice for the user Can get input Can customize buttons swing.JOptionPane.showMessageDialog(null, "Eggs are not supposed to be green."); input = swing.JOptionPane.showInputDialog(“Enter an integer:”);

GUI Interaction Radio Buttons Only one matters Action listener JRadioButton / Button group t = swing.JRadioButton(“True”,true); f = swing.JRadioButton(“False”); bg = swing.ButtonGroup(); bg.add(t); bg.add(f); //Add bg to a panel You can add a listener to t,f just like with regular JButtons

GUI Interaction Images Stuff inside of a JLabel icon = swing.ImageIcon(“filename.jpg”); test = swing.JLabel(“Image description”, icon); //Add test to a panel Same directory as where the.java files are Constants: SwingConstants.CENTER/LEFT/RIGHT/BOTTOM Image: 3 rd parameter Label text: setHorizontal/VerticalPosition

GUI Interaction Others Sliders/Checkboxes Look at the Javadocs! Learn to learn on your own Not easy, but worthwhile

GUI Interaction Summary Interactivity Global Event handler function How to design GUIs Other components