Graphical User Interface Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University
|
|
- Horatio Watkins
- 6 years ago
- Views:
Transcription
1 Graphical User Interface Programming Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University 1
2 Objectives You will learn about: Graphical user interface (GUI) programming Specifically... For Java: The AWT/Swing GUI library For Python: The Tkinter GUI library 2
3 Objectives More specifically You will learn about: High-level GUI programming Programming with buttons, menus, text fields, You will not learn about: Low-level GUI programming Drawing lines, circles, rectangles, etc. See COS 126 3
4 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 4
5 GUI Pgmming in COS 333 Option 1: Run on CourseLab User 1 Local Computer X Window Server X Windows Firewall courselab01/02 App (User 1) User 2 Local Computer X Window Server X Windows App (User 2) 5
6 GUI Pgmming in COS 333 Option 1: Run on CourseLab Must install X Window System Server on local computer See instructions in the A Computing Environment for COS 333 Assignments document from 1 st lecture 6
7 GUI Pgmming in COS 333 Option 2: Run on your computer User 1 Local Computer App User 2 Local Computer App 7
8 GUI Pgmming in COS 333 Option 2: Run on your computer Must install Java (with AWT/Swing) or Python (with Tkinter) on your computer Caveats: Make sure you install proper version Java SE 8 or Python 2.7 Asgt 2 must work on CourseLab 8
9 Java AWT/Swing Brief History Abstract Window Toolkit (AWT) JDK 1.0 Delegates painting/behavior of each GUI component to the native GUI toolkit, e.g.: Mac: Cocoa MS Windows: Win32 API or Win64 API Linux: Xlib Library constrained to greatest common denominator approach Components could behave (somewhat) differently on different computers 9
10 Java AWT/Swing Brief History Swing J2SE 1.2 Built on top of AWT architecture Relies on underlying native GUI toolkit to paint windows Paints components itself onto blank windows Library not constrained to greatest common denominator Components do behave the same on any computer Bonus: Application/user can choose look-and-feel 10
11 AWT/Swing Window Structure JFrame JPanel JPanel JFrame contains JPanel(s) Each JPanel contains Component(s) 11
12 AWT/Swing Pgm Structure See HelloSwing.java Create class to implement Runnable Create run() method within class Create JFrame object within run() method Create JPanel object and add to JFrame object Create JLabel object and add to JPanel object 12
13 AWT/Swing Pgm Structure main() method: Creates new Runnable object Passes to EventQueue.invokeLater() EventQueue.invokeLater() method starts event loop in a new thread Generalizing Suggestion: accept as a pattern More details in Threads lecture 13
14 Python Tkinter Brief History Tcl Tk Very successful scripting language John Ousterhout (Stanford U.) Cross-platform GUI toolkit Developed for Tcl 14
15 Python Tkinter Brief History Tkinter Python interface to TK ( Tk interface ) Python wrapper around Tk The standard Python GUI library Distributed with Python Other Python GUI options are available 15
16 Toplevel Tkinter Window Structure Frame Frame Toplevel (optionally) contains Frame(s) Each Frame contains Widget(s) 16
17 Tkinter Program Structure See hellotkinter.py Tk constructor creates a Toplevel object (referenced by root) Create Label object and add to root object Don t really need Frame object root.mainloop() method call starts event handling loop Generalizing Suggestion: accept as a pattern 17
18 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 18
19 Swing Component Example See ComponentTest.java JFrame, JPanel JButton, JLabel, JTextField, JTextArea, JScrollPane, JScrollBar, JSlider, JCheckBox,ButtonGroup, JRadioButton, Border, JComboBox JMenuBar, JMenu, JMenuItem, JPopupMenu JToolBar Tool tips 19
20 Swing Components java.lang.object java.awt.component java.awt.container java.awt.window java.awt.frame javax.swing.jframe java.awt.dialog javax.swing.jdialog javax.swing.jcomponent javax.swing.jpanel javax.swing.jtextcomponent javax.swing.jtextfield javax.swing.jtextarea javax.swing.jlabel javax.swing.jscrollpane javax.swing.jscrollbar javax.swing.jslider javax.swing.jcombobox java.awt.abstractbutton javax.swing.jbutton javax.swing.jtogglebutton javax.swing.jradiobutton javax.swing.jmenuitem javax.swing.jmenu javax.swing.jmenubar 20
21 Tkinter Widget Example See widgettest.py Label Button, Checkbutton, Radiobutton Entry Listbox Scale, Scrollbar Menu Text, ScrolledText Generalizing... 21
22 Tkinter Widgets object BaseWidget (and Pack, Grid, Place) Widget Label Button Checkbutton Radiobutton Entry Listbox Scale Scrollbar Text ScrolledText Menu Frame BaseWidget (and Wm) Toplevel 22
23 Tkinter Widgets Constructor arguments: First argument (usually) is parent Frame (or parent Toplevel) Subsequent arguments set properties Each widget has properties After construction, use widget['property'] to get or set a property 23
24 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 24
25 AWT Layout Manager Examples See FlowLayoutTest.java FlowLayout Flow is maintained as window resizes 25
26 AWT Layout Manager Examples See BorderLayoutTest.java BorderLayout North and south border: sizes are fixed vertically, expand horizontally East and west border: sizes are fixed horizontally, expand vertically Center expands both horizontally and vertically 26
27 AWT Layout Manager Examples See GridLayoutTest.java GridLayout Components arranged in 2-D grid 27
28 AWT Layout Managers And others; example... GridBagLayout The mother of all layout managers Horstmann Beyond COS 333 scope (Unnecessary for assignments) Generalizing... 28
29 AWT Layout Managers java.lang.object java.awt.flowlayout java.awt.borderlayout java.awt.gridlayout java.awt.gridbaglayout java.awt.boxlayout java.awt.cardlayout java.awt.grouplayout java.awt.overlaylayout java.awt.scrollpanelayout java.awt.springlayout java.awt.viewportlayout 29
30 Tkinter Layout Mgr Example See packertest.py Pack class, pack() method Widget inherits from Pack Can send pack() message to any Widget object to pack it within its parent Widget 30
31 Tkinter Layout Manager Pack layout manager Same functionality as AWT BorderLayout... North and south border: sizes (typically) are fixed vertically, expand horizontally East and west border: sizes (typically) are fixed horizontally, expand vertically Center (typically) expands both horizontally and vertically 31
32 Tkinter Layout Mgr Example See griddertest.py Grid class, grid() method Widget inherits from Grid Can send grid() message to any Widget object to grid it within its parent object 32
33 Tkinter Layout Manager Grid layout manager Same functionality as AWT GridLayout... Components arranged in 2-D grid 33
34 Tkinter Layout Manager And one more... Place Low-level layout manager Places widgets within parent exactly as the widget requires Used to implement custom layout managers Beyond the scope of COS 333 Generalizing... 34
35 Tkinter Layout Managers object Pack Grid Place 35
36 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 36
37 AWT Event Handling Example Show EventTest1.java JButton event handling Event handling for other components is similar Listener object must access panel Generalizing... 37
38 AWT Event Handling Problem Problem: Listener object often must access Components other than the one generating the event Awkward to pass Components to Listener constructor Solution: 38
39 AWT Event Handling Example See EventTest2.java ColorActionListener2 is an inner class Defined within EventTestRunnable2 ColorActionListener2 object can access fields of EventTestRunnable2 objects 39
40 Inner Class Commentary Inner class commentary: Q: Use inner classes? A: I vote yes Inner classes yield more succinct code Additional language complexity is minimal 40
41 Semantic events: AWT Event Handling Component AbstractButton JComboBox JTextField JScrollBar JSlider Listener Interface Its Methods ActionListener actionperformed() AdjustmentListener adjustmentvaluechanged() ChangeListener statechanged() Parameter Some of Its Methods ActionEvent getsource(), getactioncommand(), getmodifiers() AdjustmentEvent getsource(), getadjustable(), getvalue(), getadjustmenttype() ChangeEvent getsource() AbstactButton JComboBox ItemListener itemstatechanged() ItemEvent getsource(), getitem(), getstatechange(), getitemselectable() 41
42 Low-level events: AWT Event Handling Component Listener Interface Its Methods Parameter Some of its Methods Component FocusListener focusgained() focuslost() FocusEvent getsource(), istemporary() Component KeyListener keypressed() keyreleased() keytyped() KeyEvent getsource(), getkeychar(), getkeycode(), isaltdown(), iscontroldown(), ismetadown(), isshiftdown(), getkeymodifierstext(), getkeytext(), isactionkey() Component MouseListener mousepressed() mousereleased() mouseentered() mouseexited() mouseclicked() MouseEvent getsource(), getmodifiers(), isaltdown(), iscontroldown(), ismetadown(), isshiftdown(), getclickcount(), getx(), gety(), getpoint(), translatepoint() Component MouseMotionListener mousedragged() mousemoved() MouseEvent getsource() 42
43 Low-level events: AWT Event Handling Component Component Window Window Window Listener Interface Its Methods MouseWheelListener mousewheelmoved() WindowListener windowclosing() windowopening() windowopened() windowiconified() windowdeiconified() windowclosed() windowactivated() windowdeactivated() WindowFocusListener windowgainedfocus() windowlostfocus() WindowStateListener windowstatechanged() Parameter Some of its Methods MouseWheelEvent getsource(), getwheelrotation(), getscrollamount() WindowEvent getsource(), getcomponent(), getwindow() WindowEvent getsource(), getcomponent(), getwindow() WindowEvent getsource(), getoldstate(), getnewstate() 43
44 AWT Event Handling Example See EventTestAll.java AWT informs JComponent and Window objects of many events 44
45 Tkinter Event Handling Example See eventtest1.py Set command property of each Button object Function callback mechanism Click on button => call registered command function global statement Defines root variable to be global Callback functions can access root variable 45
46 Tkinter Event Handling Problem Problem: Callback functions often must access widgets Very poor style to use global variables Solution: 46
47 Tkinter Event Handling Example See eventtest2.py Inner function definitions In spirit, similar to Java s inner class definition Inner function can access variables that are local to containing function/method 47
48 Tkinter Event Handling Example See eventtesteach.py Common patterns, per Widget Generalizing... Three non-disjoint mechanisms 48
49 Tkinter Event Handling Command mechanism For Button, Radiobutton, Checkbutton, Menu Define zero-arg callback function Assign callback function to Widget command property Similar to Java Swing semantic event handling 49
50 Tkinter Event Handling Variable object mechanism For Checkbutton, Radiobutton, Entry, Scale Define Tkinter variable object IntVar, DoubleVar, StringVar Assign Tkinter variable object to Widget via variable or textvariable property User affects Widget => affects variable obj Program affects variable obj => affects Widget No Java Swing equivalent 50
51 Tkinter Event Handling Bind mechanism For any Widget Define callback function with event as param Send bind() message to Widget object with event pattern and callback function as args Similar to Java Swing low-level event handling 51
52 Tkinter Event Patterns First argument to bind() specifies an event pattern '<MODIFIER-MODIFIER-TYPE-DETAIL>' MODIFIER: Control, Alt, Double, Triple, Button1, B1, Button2, B2, Button3, B3, Button4, B4, Button5, B5 M, Mod1, M1, Mod2, M2, Mod3, M3, Mod4, M4, Mod5, M5, Shift, Lock, Meta, TYPE: KeyPress, Key, KeyRelease, ButtonPress, Button, ButtonRelease, Motion, Enter, Leave, FocusIn, FocusOut, Destroy, MouseWheel, Activate, Map, Expose, Circulate, Property, Colormap, Gravity, Reparent, Configure, Unmap, Deactivate, Visibility DETAIL: For KeyPress, Key, KeyRelease: the Keysym For ButtonPress, Button, ButtonRelease: the button number 52
53 Tkinter Event Patterns Keysym a, b, 0, 1, F1, F2, Left, Right, Up, Down, End, Home, Insert, Print, Tab, Escape, Return, Caps_Lock, Num_Lock, Scroll_Lock space, less Button Number (MS Windows and Linux) 1 (the primary/left mouse button) 2 (the scroll wheel mouse button) 3 (the secondary/right mouse button) Button Number (Mac) 1 (the primary/left mouse button) 2 (the secondary/right mouse button) 3 (the scroll wheel mouse button) 53
54 Tkinter Event Pattern Examples widget.bind('<button>', f) Call f() when user clicks a mouse button widget.bind('<key>', f) Call f() when user types a key widget.bind('<double-button-1>, f) Call f() when user double clicks the left mouse button widget.bind('<control-key-a>', f) Call f() when user types Ctrl-a 54
55 Tkinter Event Handling Example See eventtestall.py Tkinter informs Widget objects of many events 55
56 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 56
57 Swing Dialogs See OptionPaneMessageTest.java JOptionPane See OptionPaneConfirmTest.java JOptionPane See OptionPaneOptionTest.java JOptionPane See OptionPaneInputTest.java JOptionPane 57
58 Swing Dialogs See FileChooserTest.java JFileChooser See ColorChooserTest.java JColorChooser Generalizing... 58
59 Swing Dialogs java.lang.object java.awt.component java.awt.container java.awt.window java.awt.frame javax.swing.jframe java.awt.dialog javax.swing.jdialog javax.swing.jcomponent javax.swing.jpanel javax.swing.jtextcomponent javax.swing.jtextfield javax.swing.jtextarea javax.swing.jlabel javax.swing.jscrollpane javax.swing.jscrollbar javax.swing.jslider javax.swing.jcombobox java.awt.abstractbutton javax.swing.jbutton javax.swing.jtogglebutton javax.swing.jradiobutton javax.swing.jmenuitem javax.swing.jmenu javax.swing.jmenubar javax.swing.joptionpane javax.swing.jfilechooser javax.swing.jcolorchooser 59
60 Tkinter Dialogs See messageboxtest.py tkmessagebox module See simpledialogtest.py tksimpledialog module See filedialogtest.py tkfiledialog module See colorchoosertest.py tkcolorchooser module 60
61 Tkinter Dialogs Generalizing: tkmessagebox module askokcancel() askquestion() askretrycancel() askyesno() showerror() showinfo() showwarning() tksimpledialog askfloat() askinteger() askstring() tkfiledialog module askdirectory() askopenfilename() askopenfilenames() asksaveasfilename() tkcolorchooser module askcolor() 61
62 Agenda Introduction Components/widgets Layout managers Event handling Dialogs Conclusion 62
63 AWT/Swing Example See ColorDisplayer.java Slightly larger and more realistic Multiple interacting components Note: Components Layout (and resizing behavior) Event handling 63
64 AWT/Swing Example ColorDisplayer.java component composition hierarchy: frame (uses BorderLayout) colorpanel controlpanel (uses BorderLayout) labelpanel (uses GridLayout) redlabel greenlabel bluelabel sliderpanel (uses GridLayout) redslider greenslider blueslider textfieldpanel (uses GridLayout) redtextfield greentextfield bluetextfield 64
65 Tkinter Example See colordisplayer.py Slightly larger and more realistic Multiple interacting widgets Note: Widgets Layout (and resizing behavior) Event handling 65
66 Tkinter Example colordisplayer.py widget composition hierarchy: root (uses Pack) colorframe controlframe (uses Grid) redlabel greenlabel bluelabel redscale greenscale bluescale redentry greenentry blueentry 66
67 Getting More Info: AWT/Swing Javadocs java/awt/package-summary.html javax/swing/package-summary.html Horstmann book Additional resources referenced in Topics web page 67
68 Getting More Info: Tkinter $ python >>> from Tkinter import * >>> from ScrolledText import * >>> help(toplevel) >>> help(widget) >>> help(button) >>> help(scrolledtext) >>> help(event)... Additional resources referenced in Topics web page 68
69 Summary We have covered: Graphical user interface (GUI) programming Specifically... For Java: The AWT/Swing GUI library For Python: The Tkinter GUI library 69
70 Summary For each: Introduction Components Layout managers Event handling Dialogs Conclusion 70
71 Summary Not covered... Low-level drawing For Java: the Java 2D library For Python: the Canvas class 71
72 Appendix 1: Graphical User Interfaces in C 72
73 GUIs in C For C/Unix/Linux... The X-Window GUI library X-Window server runs on local computer X-Window client runs on server computer See srcs/helloxsrc.html Use -lx11 option to build Explicit coding of event loop 73
74 GUIs in C Higher level GUI modules exist For example... GTK+ See 74
75 Appendix 2: Bad GUIs 75
76 Bad GUIs Some collected by Prof. Kernighan... 76
77 Bad GUIs 77
78 Bad GUIs 78
79 Bad GUIs 79
80 Bad GUIs 80
81 Bad GUIs 81
82 Bad GUIs 82
83 Bad GUIs 83
84 Bad GUIs The Interface Hall of Shame mode=original Some from that website 84
85 Bad GUIs 85
86 Bad GUIs 86
87 Bad GUIs 87
88 Bad GUIs 88
89 Bad GUIs 89
Graphical User Interface Programming. Copyright 2018 by Robert M. Dondero, Ph.D. Princeton University
Graphical User Interface Programming Copyright 2018 by Robert M. Dondero, Ph.D. Princeton University 1 Objectives You will learn about: Graphical user interface (GUI) programming Specifically... For Java:
More information2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING
2010 가을학기부산대학교정보컴퓨터공학부 OVERVIEW OF GUI PROGRAMMING Outline Graphic User Interface (GUI) Introduction AWT and Swing Graphics Programming Event Handling User Interface Components with Swing 2 Graphic User
More informationMarcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science
Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Abstract Window Toolkit Delegates creation and
More informationJava Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing
Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/
More informationChapter 6: Graphical User Interfaces
Chapter 6: Graphical User Interfaces CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 6: Graphical User Interfaces CS 121 1 / 36 Chapter 6 Topics
More information11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events
Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationJava: Graphical User Interfaces (GUI)
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application
More informationGUI Software Architecture
GUI Software Architecture P2: Requirements Analysis User Analysis Task Analysis Problem Scenarios Usability Criteria Scenario Your engineers just developed a new desktop computer. They give you the following
More informationDr. Hikmat A. M. AbdelJaber
Dr. Hikmat A. M. AbdelJaber GUI are event driven (i.e. when user interacts with a GUI component, the interaction (event) derives the program to perform a task). Event: click button, type in text field,
More informationAdvanced Java Programming (17625) Event Handling. 20 Marks
Advanced Java Programming (17625) Event Handling 20 Marks Specific Objectives To write event driven programs using the delegation event model. To write programs using adapter classes & the inner classes.
More informationSystems Programming Graphical User Interfaces
Systems Programming Graphical User Interfaces Julio Villena Román (LECTURER) CONTENTS ARE MOSTLY BASED ON THE WORK BY: José Jesús García Rueda Systems Programming GUIs based on Java
More informationCSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More information10/16/2008. CSG 170 Round 5. Prof. Timothy Bickmore. User Analysis Task Analysis (6) Problem Scenarios (3)
Human-Computer Interaction CSG 170 Round 5 Prof. Timothy Bickmore T2: Requirements Analysis Review User Analysis Task Analysis (6) Problem Scenarios (3) 1 T2 Review Requirements Analysis Who is the user?
More informationPIC 20A GUI with swing
PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args
More informationCSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationGraphical User Interfaces in Java - SWING
Graphical User Interfaces in Java - SWING Graphical User Interfaces (GUI) Each graphical component that the user can see on the screen corresponds to an object of a class Component: Window Button Menu...
More informationProgramming graphics
Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it
More informationSummary Chapter 25 GUI Components: Part 2
1040 Chapter 25 GUI Components: Part 2 ponent on the line. TheJTextField is added to the content pane with a call to our utility method addcomponent (declared at lines 79 83). MethodaddComponent takes
More informationCS 251 Intermediate Programming GUIs: Event Listeners
CS 251 Intermediate Programming GUIs: Event Listeners Brooke Chenoweth University of New Mexico Fall 2017 What is an Event Listener? A small class that implements a particular listener interface. Listener
More informationCourse Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University March 10, 2008 / Lecture 8 Outline Course Status Course Information & Schedule
More informationGUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)
Objectives Write code to handle events that occur in a GUI 11 GUI Event Handling Describe the concept of adapter classes, including how and when to use them Determine the user action that originated the
More informationLecture 18 Java Graphics and GUIs
CSE 331 Software Design and Implementation The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction Lecture 18 Java Graphics and GUIs None
More informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationTable of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...
Table of Contents Chapter 1 Getting Started with Java SE 7 1 Introduction of Java SE 7... 2 Exploring the Features of Java... 3 Exploring Features of Java SE 7... 4 Introducing Java Environment... 5 Explaining
More informationCS 251 Intermediate Programming GUIs: Components and Layout
CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()
More informationJava Event Handling -- 1
Java Event Handling -- 1 Event Handling Happens every time a user interacts with a user interface. For example, when a user pushes a button, or types a character. 2 A Typical Situation: Scrollbar AWTEvent
More informationGraphical User Interfaces. Comp 152
Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from
More information12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.
} Radio buttons (declared with class JRadioButton) are similar to checkboxes in that they have two states selected and not selected (also called deselected). } Radio buttons normally appear as a group
More informationCOMPSCI 230. Software Design and Construction. Swing
COMPSCI 230 Software Design and Construction Swing 1 2013-04-17 Recap: SWING DESIGN PRINCIPLES 1. GUI is built as containment hierarchy of widgets (i.e. the parent-child nesting relation between them)
More informationHandout 14 Graphical User Interface (GUI) with Swing, Event Handling
Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement
More informationCS11 Java. Fall Lecture 3
CS11 Java Fall 2014-2015 Lecture 3 Today s Topics! Class inheritance! Abstract classes! Polymorphism! Introduction to Swing API and event-handling! Nested and inner classes Class Inheritance! A third of
More informationSD Module-1 Advanced JAVA
Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program
More informationGUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline
Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example
More informationAll the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.
Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space
More informationJava GUI Design: the Basics
Java GUI Design: the Basics Daniel Brady July 25, 2014 What is a GUI? A GUI is a graphical user interface, of course. What is a graphical user interface? A graphical user interface is simply a visual way
More informationSD Module-1 Advanced JAVA. Assignment No. 4
SD Module-1 Advanced JAVA Assignment No. 4 Title :- Transform the above system from command line system to GUI based application Problem Definition: Write a Java program with the help of GUI based Application
More informationBuilding a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver
Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components
More informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Java Graphics and GUIs 1 The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction
More informationPart 3: Graphical User Interface (GUI) & Java Applets
1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ
More informationExample Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.
COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationGUI Programming: Swing and Event Handling
GUI Programming: Swing and Event Handling Sara Sprenkle 1 Announcements No class next Tuesday My Fourth of July present to you: No quiz! Assignment 3 due today Review Collections: List, Set, Map Inner
More informationPROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7
PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,
More informationBasicsof. JavaGUI and SWING
Basicsof programming3 JavaGUI and SWING GUI basics Basics of programming 3 BME IIT, Goldschmidt Balázs 2 GUI basics Mostly window-based applications Typically based on widgets small parts (buttons, scrollbars,
More informationGUI Event Handlers (Part II)
GUI Event Handlers (Part II) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda Listener
More informationGraphic User Interfaces. - GUI concepts - Swing - AWT
Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations
More informationChapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.
Chapter 8 Java continued CS3283 - Hugh Anderson s notes. Page number: 263 ALERT MCQ test next week This time This place Closed book CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Assignment #2
More informationJava continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3
Chapter 8 Java continued MCQ test next week This time This place Closed book ALERT CS3283 - Hugh Anderson s notes. Page number: 263 CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Last week Assignment
More informationGUI in Java TalentHome Solutions
GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator
More informationControl Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User
CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by
More informationCS11 Java. Fall Lecture 4
CS11 Java Fall 2006-2007 Lecture 4 Today s Topics Interfaces The Swing API Event Handlers Inner Classes Arrays Java Interfaces Classes can only have one parent class No multiple inheritance in Java! By
More informationGoals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords
Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup
More informationThe AWT Event Model 9
The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow
More informationIntroduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008
Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive
More informationStarting Out with Java: From Control Structures Through Objects Sixth Edition
Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes
More informationSwing. By Iqtidar Ali
Swing By Iqtidar Ali Background of Swing We have been looking at AWT (Abstract Window ToolKit) components up till now. Programmers were not comfortable when doing programming with AWT. Bcoz AWT is limited
More informationDatenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1
Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text
More informationCPS122 Lecture: Graphical User Interfaces and Event-Driven Programming
CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised 1/15/10 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField, JTextArea,
More informationSwing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff
Swing UI by Vlad Costel Ungureanu for Learn Stuff User Interface Command Line Graphical User Interface (GUI) Tactile User Interface (TUI) Multimedia (voice) Intelligent (gesture recognition) 2 Making the
More informationJava & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn
Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event
More information2110: GUIS: Graphical User Interfaces
2110: GUIS: Graphical User Interfaces Their mouse had a mean time between failure of a week it would jam up irreparably, or... jam up on the table--... It had a flimsy cord whose wires would break. Steve
More informationLecture 5: Java Graphics
Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,
More informationGraphical User Interfaces (GUIs)
CMSC 132: Object-Oriented Programming II Graphical User Interfaces (GUIs) Department of Computer Science University of Maryland, College Park Model-View-Controller (MVC) Model for GUI programming (Xerox
More information14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS
550 Chapter 14 GUI Components: Part 1 14.1 Introduction 14.2 Java s New Nimbus Look-and-Feel 14.3 Simple GUI-Based Input/Output with JOptionPane 14.4 Overview of Swing Components 14.5 Displaying Text and
More informationCONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13
CONTENTS Chapter 1 Getting Started with Java SE 6 1 Introduction of Java SE 6... 3 Desktop Improvements... 3 Core Improvements... 4 Getting and Installing Java... 5 A Simple Java Program... 10 Compiling
More informationBASICS OF GRAPHICAL APPS
CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In
More informationPackages: Putting Classes Together
Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic
More informationGraphical interfaces & event-driven programming
Graphical interfaces & event-driven programming Lecture 12 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 Pop quiz!
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationGraphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)
Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build
More informationAnnouncements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation Lecture 18 Java Graphics and GUIs Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Regression testing
More information(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI
51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface
More information17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau
List of Slides 1 Title 2 Chapter 13: Graphical user interfaces 3 Chapter aims 4 Section 2: Example:Hello world with a GUI 5 Aim 6 Hello world with a GUI 7 Hello world with a GUI 8 Package: java.awt and
More informationProgramming Training. This Week: Tkinter for GUI Interfaces. Some examples
Programming Training This Week: Tkinter for GUI Interfaces Some examples Tkinter Overview Set of widgets designed by John K. Ousterhout, 1987 Tkinter == Tool Kit Interface Mean to be driven by Tcl (Toolkit
More informationSummary. Section 14.1 Introduction. Section 14.2 Java s New Nimbus Look-and-Feel. 618 Chapter 14 GUI Components: Part 1
618 Chapter 14 GUI Components: Part 1 erence to a JScrollPane, the program can use JScrollPane methods sethorizontal- ScrollBarPolicy and setverticalscrollbarpolicy to change the scrollbar policies at
More informationIntroduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014
Introduction to GUIs Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2014 Slides copyright 2014 by Jonathan Aldrich, Charlie Garrod, Christian
More informationCSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing
CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic
More informationSri Vidya College of Engineering & Technology
UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language
More informationEvent Driven Programming
Event Driven Programming 1. Objectives... 2 2. Definitions... 2 3. Event-Driven Style of Programming... 2 4. Event Polling Model... 3 5. Java's Event Delegation Model... 5 6. How to Implement an Event
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationAssignment No 2. Year: Dept.: ComputerTech. Sanjivani Rural Education Society s Sanjivani KBP Polytechnic, Kopargaon
Year: 015-16 ACAD/F/3 Subject: AJP(1765) Division:CMTA(CM6G) Pages: 1-7 CHAPTER :Event Handling(0 Marks) Q.1 package contains all the classes and methods required for Event handling in java. (a) java.applet
More informationBuilding Java Programs Bonus Slides
Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog
More informationGUI Event Handlers (Part I)
GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event
More informationGraphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI
CBOP3203 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others.
More informationChapter 12 Advanced GUIs and Graphics
Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program
More informationTool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT
INSTITUTIONEN FÖR Tool Kits, Swing SMD158 Interactive Systems Spring 2005 Jan-28-05 2002-2005 by David A. Carr 1 L Overview Tool kits in the abstract An overview of Swing/AWT Jan-28-05 2002-2005 by David
More informationJonathan Aldrich Charlie Garrod
Principles of Software Construction: Objects, Design, and Concurrency (Part 3: Design Case Studies) Introduction to GUIs Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework
More informationGraphical User Interfaces. Swing. Jose Jesus García Rueda
Graphical User Interfaces. Swing Jose Jesus García Rueda Introduction What are the GUIs? Well known examples Basic concepts Graphical application. Containers. Actions. Events. Graphical elements: Menu
More informationJava Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1
Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes
More informationJTcl and Swank. Bruce A. Johnson, Tom Poindexter, & Dan Bodoh. What s new with Tcl and Tk on the JVM. Wednesday, October 26, 11
JTcl and Swank What s new with Tcl and Tk on the JVM Bruce A. Johnson, Tom Poindexter, & Dan Bodoh JTcl and Swank Bruce s Motivation Cross-platform, scriptable, desktop applications for analyzing and visualizing
More informationGUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */
25 4 GUI GUI GUI 4.1 4.1.1 MouseTest.java /* 1 */ public class MouseTest extends JApplet implements MouseListener /* 2 */ { int x=50, y=20; addmouselistener(this); /* 3 */ super.paint(g); /* 4 */ g.drawstring("hello
More informationGUI DYNAMICS Lecture July 26 CS2110 Summer 2011
GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain
More informationCPS122 Lecture: Graphical User Interfaces and Event-Driven Programming
CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised March 2, 2017 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField,
More informationCOSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware
More informationUI Software Organization
UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app
More informationBean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication
COMP434B Software Design JavaBeans: Events and Reflection Events are the primary mechanism by which Java components interact with each other One Bean generates an event and one or more other Beans receive
More information