Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.

Slides:



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

User Interfaces II GUI – Awt, Swing, Web
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
Graphical User Interfaces
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Drawing in a frame – Java GUI
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
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.
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 Foundation Classes (JFC/Swing) Carl Alphonce revised Spring 2007 (with contributions from Alan Hunt)
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Agenda –interfaces and realization –type hierarchy –introduction to graphics and event handling.
Things to mention public static void main(String [] args) imports comments –block comments /* … */ –single-line comments // –javadoc comments and tags.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
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 
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, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
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.
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.
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.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
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.
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.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
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.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
Multiple buttons and action calls
Graphical User Interfaces
A First Look at GUI Applications
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
EE 422C Java FX.
Steps to Creating a GUI Interface
Graphical User Interface
Presentation transcript:

Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions pane) imports –Allow us to use, with unqualified names, things defined in other packages comments – ignored by the compiler –block comments /* … */ –single-line comments // –javadoc comments and tags (?) /** … */ CSE 115/503 Introduction to Computer Science for Majors I1

Using the Java graphics classes In this slide set we will explain the basics of how to create graphical programs. Some advanced issues will be glossed over (e.g. thread safety, graphics library design). In CSE116 we will revisit these and other more advanced topics. CSE 115/503 Introduction to Computer Science for Majors I2

Graphical elements There are two basic types of graphical elements: –Containers able to hold graphical objects, such as containers and components –Components must be put into containers able to generate events when manipulated CSE 115/503 Introduction to Computer Science for Majors I3

Containers Top-level containers –some containers are called “top-level” because they do not need to be place inside any other containers –javax.swing.JFrame is an example (JDialog and JApplet are others) Other containers (not top-level) –most containers must be placed inside some other container –javax.swing.JPanel is an example CSE 115/503 Introduction to Computer Science for Majors I4

Adding elements to a JFrame Top-level containers have multiple panes Content pane is the one which holds components With javax.swing.JFrame, two ways: –call getContentPane() on frame to get frame’s content pane, then call add(…) on content pane to add a component –call add(…) directly on the JFrame object Second approach is just a convenience method, does the same thing the first approach 5

CSE 115/503 Introduction to Computer Science for Majors I Example Creating just a frame –new javax.swing.JFrame() Creating a frame with a title –new javax.swing.JFrame(“My title”) Making the frame visible –call setVisible(true) on the frame Making application close when window is closed: –call setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) on the frame See code in: –the BasicExample class in the graphics package of the GraphicsExamples project in the repository, as well as, –the ex_1_JFrame_visible package in the FA10-CSE115-SwingExamples project in the repository. 6

CSE 115/503 Introduction to Computer Science for Majors I A simple component A JLabel is a component that can display text or an image. It can also have a “tooltip”, a note that appears when you hover the mouse pointer over it, without clicking. Look at ex_2_JLabel_tooltip 7

CSE 115/503 Introduction to Computer Science for Majors I Layout managers First, let’s consider what happens if we add another JLabel to the content pane of the JFrame. Look at ex_3_JLabels_noLayout This will show us the need to manage the layout of components added to a container. See also code in GraphicsExamples project for this and the rest of the slides. 8

Applying a layout management strategy Look at ex_4_staticLayout In this example we can apply one of four different layout management strategies to a set of seven JLabels that are added to the JFrame’s content pane. CSE 115/503 Introduction to Computer Science for Majors I9

Another component: a JButton A JButton is a component which is typically set up to react to clicks. Look at ex_5_JButton_noEventHandler, this example just shows a JButton. 10

Events Clicks on buttons, mouse movements, etc. are all considered events. A program can react to events by setting up event handlers. An event handler defines what should happen when a particular event occurs. CSE 115/503 Introduction to Computer Science for Majors I11

CSE 115/503 Introduction to Computer Science for Majors I Event handling – 1 The component which gives rise to an event is decoupled from the part of the code that handles the event. This is called the observer pattern. General form: – 12

CSE 115/503 Introduction to Computer Science for Majors I Event handling – 2 Observer pattern in Java –An observer is called a listener in Java –Button clicks are “ActionEvents”. –Handlers for ActionEvents are ActionListeners. –An event-generator can have many listeners –Use “addActionListener” method to register a listener with a component 13

CSE 115/503 Introduction to Computer Science for Majors I Event handling for a JButton Look at ex_6_JButton_eventHandler In this example an event handler is defined and attached to the JButton. 14

CSE 115/503 Introduction to Computer Science for Majors I Putting it all together Look at ex_7_dynamicLayoutEventHandling In this example we put everything together: –different components are put into different containers –multiple components are put into each container –different layout managers can be applied dynamically –JButtons’ event handlers select and apply different layout managers to the container containing JLabels 15