Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
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.
Event Handling Events and Listeners Timers and Animation.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 16 Java Fundamentals Java2 Graphical User Interfaces.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
Graphical User Interfaces Allow for interaction with –Buttons –Menus –Text Fields Two Java Libraries to assist in GUI Programming –AWT –Swing.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
Java Swing 4 th April 2008 CS 180 Department of Computer Science, Purdue University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 14 GUI and Event-Driven Programming.
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.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
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,
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Chapter 12- GUI’s, Java, and Swing.. Overview n What are GUI’s n How Java does GUI’s- Swing n Buttons n Containers n Text I/O and Swing n Review.
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 GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
Java Programming 1 Java Programming II Events, AWT, and Swing.
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.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
CS Lecture 01 Frames and Components and events Lynda Thomas
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
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.
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.
Layout Managers Arranges and lays out the GUI components on a container.
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.
Pravin Yannawar, DOCS, NMU Jalgaon. Basic Java : Event handling in AWT and Swing 2 Objectives of This Session Explain the Event handling mechanism & demonstrate.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Event-Driven Programming and GUIs l Swing Basics and.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Event Handling.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 10: Event Handling 1 Chapter 10 Event Handling.
Computer Science 209 GUIs Model/View/Controller Layouts.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
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 Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
A Quick Java Swing Tutorial
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Object-Orientated Analysis, Design and Programming
Web Design & Development Lecture 11
GUIs Model/View/Controller Layouts
Graphical User Interface (pronounced "gooey")
CSE 114 – Computer Science I Event Programming
Ellen Walker Hiram College
Event-driven programming for GUI
Web Design & Development Lecture 12
Window Interfaces Using Swing Objects Chapter 12
Graphical User Interface
Presentation transcript:

Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington

Simple Gui layout Design Four main decisions 1. User Interactions what to gather from user, what to show him 2. Particular objects on screen JTextField, TextArea, JButton, JPanels, JLabels, JFrame General layout of Screen borderlayout, gridlayout, flowlayout,…. 4. Listeners connect user actions with program activities WindowListeners, ActionListeners, ItemListeners, ….

Minimal Objects and methods JFrame: where you start –Container mainPane = getContentPane() is where you add other components. JPanels: –container for other objects including Jpanels –setLayoutManager(..) JTextField(int size): setText, getText, addActionListener TextArea(int row, int col): append JButton(String s): named button, addActionListener JLabel(String s): just a string More: JTabbedPane, ScollBars, Lists, Checkboxes, Menus, Dialogs, PopUps, Sliders,Toolbars…..and on and on

Layout Managers FlowLayout() –right to left with wrap around –default manager for JPanel BorderLayout() –north, south, east, west, center –default for contentPane GridLayout(int row, int columns) –row and columns GridBag Layout (..) –hurts my head Layout Managers can be nested.

Listeners are Interfaces WindowListeners –respond to window events, such as miniminizing window, closing, moving, maximizing, etc. –Window will not Close! Need to add a listener. –Has 7 methods, I.e. obligations. ActionListeners –For JButtons, responds to clicking on buttons –For JTextFields, responds to “enter” –Still need to define the activity –Only 1 method: actionPerformed(ActionEvent ae) ItemListeners, MouseListeners, KeyListeners,…. 11 listeners at last count.

Events ActionEvent –button pressed, text entered, …. WindowEvent –windowIconified, windowClosed, windowOpened,… Key Events: –keyTyped, keyPressed, keyReleased MouseEvents: –mouseClicked, mousePressed, mouseReleased, mouseDragged, mouseMoved,... TextEvent –textValue changed,.. And on and on

Closeable Hello World import javax.swing.*; // for J stuff import java.awt.event.*; // for listeners import java.awt.*; // for the layout managers class Driver extends JFrame { public static void main(String[] args) { Driver driver = new Driver(); driver.show() // without this, you get nothing } Driver() { addWindowListener(new WindowDestroyer()); //needed to close window Container mainPane = getContentPane(); // default border layout mainPane.add(new Jlabel(“Hello World”)); }

Window Destroyer import java.awt.event.*; class WindowDestroyer extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } WindowListener has 7 methods to define. WindowAdapter defines them all to do nothing.