CS 4244: Internet Programming User Interface Programming in Java 1.0.

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
Chapter 8: Graphical User Interfaces Objectives - by the end of this chapter, you should be able to do the following: –write a simple graphical user interface.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
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.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
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.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
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.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
CS Lecture 00 Swing overview and introduction Lynda Thomas
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.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Event Driven Programming. Event-driven Programming In the early days of computing communication with the outside world was accomplished using a technique.
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.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
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 – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
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.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Review_6 AWT, Swing, ActionListener, and Graphics.
Basics of GUI Programming Chapter 11 and Chapter 22.
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 Swing One of the most important features of Java is its ability to draw graphics.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
1 IM103 week 10 Enhancing the user interface By the end of lecture you should be able to:  distinguish between heavyweight and lightweight components;
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)
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.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
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:
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
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.
Graphical User Interfaces
Graphical User Interfaces
A First Look at GUI Applications
GUIs Model/View/Controller Layouts
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Week 8 Swing NetBeans GUI Builder
A Quick Java Swing Tutorial
Graphical User Interface
Presentation transcript:

CS 4244: Internet Programming User Interface Programming in Java 1.0

Java Foundation Classes (JFC) Set of classes within J2SE for GUI development and graphics JFC APIs or packages include AWT Swing Java 2D Applets Accessibility Internationalization...

Swing and AWT Architecture AWT provides Basic facilities for creating GUIs Drawing graphics Swing is newer GUI toolkit Extension of AWT All GUI components within Swing are lightweight, making it more portable Larger and more comprehensive than AWT

Simple GUI

Code for the GUI import java.awt.*; // AWT classes import javax.swing.*; // Swing components and classes import javax.swing.border.*; // Borders for Swing components import java.awt.event.*; // Basic event handling /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Code for the GUI public class DisplayMessage { public static void main(String[] args) { /* * Step 1: Create the components */ JLabel msgLabel = new JLabel(); // Component to display the question JButton yesButton = new JButton(); // Button for an affirmative response JButton noButton = new JButton(); // Button for a negative response /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Simple GUI JLabel JButton

Code for the GUI /* * Step 2: Set properties of the components */ msgLabel.setText(args[0]); // The msg to display msgLabel.setBorder(new EmptyBorder(10,10,10,10)); yesButton.setText((args.length >= 2)?args[1]:"Yes"); noButton.setText((args.length >= 3)?args[2]:"No"); /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Code for the GUI /* * Step 3: Create containers to hold the components */ JFrame win = new JFrame("Message"); // The main application window JPanel buttonbox = new JPanel(); // A container for the two buttons /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Simple GUI Jframe (win) Jpanel (buttonbox)

Code for the GUI /* * Step 4: Specify LayoutManagers to arrange components in the containers */ win.getContentPane().setLayout(new BorderLayout()); buttonbox.setLayout(new FlowLayout()); /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Simple GUI BorderLayout FlowLayout

Code for the GUI /* * Step 5: Add components to containers, with optional layout constraints */ buttonbox.add(yesButton); // add yes button to the panel buttonbox.add(noButton); // add no button to the panel // add JLabel to window, telling the BorderLayout to put it in the middle win.getContentPane().add(msgLabel, "Center"); // add panel to window, telling the BorderLayout to put it at the bottom win.getContentPane().add(buttonbox, "South"); /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Simple GUI

Code for the GUI /* * Step 6: Arrange to handle events in the user interface. */ yesButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the Yes button is clicked. public void actionPerformed(ActionEvent e) { System.exit(0); } }); noButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the No button is clicked. public void actionPerformed(ActionEvent e) { System.exit(1); } }); /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */

Code for the GUI /* * Step 6: Arrange to handle events in the user interface. */ yesButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the Yes button is clicked. public void actionPerformed(ActionEvent e) { System.exit(0); } }); noButton.addActionListener(new ActionListener() { // Note: inner class // This method is called when the No button is clicked. public void actionPerformed(ActionEvent e) { System.exit(1); } }); /* * This example is from the book "Java Foundation Classes in a Nutshell". * Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. * You may distribute this source code for non-commercial purposes only. * You may study, modify, and use this example for any purpose, as long as * this notice is retained. Note that this example is provided "as is", * WITHOUT WARRANTY of any kind either expressed or implied. */