Object-Oriented Software Engineering Java with added Swing.

Slides:



Advertisements
Similar presentations
Components and Containers
Advertisements

Java Foundation Classes (JFC/Swing) Carl Alphonce revised Spring 2007 (with contributions from Alan Hunt)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Writing GUI Applications An introduction with Java.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Graphical User Interfaces
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Creating GUIs in Java using Swing David Meredith Aalborg University.
Java Swing Joon Ho Cho. What is Java Swing? Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Graphical User Interface (GUI) Design using Swing Course Lecture Slides.
GUI Basics: Introduction. Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your.
Introduction to Java GUI Creating Graphical User Interfaces © copyright Bobby Hoggard / material may not be redistributed without permission.
Java Swing © Walter Milner 2005: Slide 1 Java Swing Walter Milner.
Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
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
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Swing [part.1] Taken from Water Milner Eriq Muhammad Adams J |
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
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.
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.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
1 Java Swing - Lecture 2 Components and Containment Boriana Koleva
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
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.
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.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Object-Oriented Software Engineering
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.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Object-Oriented Software Engineering Using Threads and simple Animation.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
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)
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
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:
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CREATING A SIMPLE GUI Mr. Crone. First GUI Today we will use Swing to create the following application:
Java Swing. Note - this presentation.. often needs to refer to source code which is too big to put on a slide So the source code is in a separate Word.
GUI 1: JFC and Swing Basics OOP tirgul No
Object-Oriented Software Engineering JFrames with Swing.
Lecture 15 Basic GUI programming
Game Engine Architecture
A First Look at GUI Applications
Game Engine Architecture
Object-Oriented Software Engineering
Steps to Creating a GUI Interface
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Object-Oriented Software Engineering Java with added Swing

UniS 2 Contents Overview of Swing components Introduction to case study example Basic structure of Java Swing application Overview of runtime execution of application

UniS 3 Swing Basics Java provides a collection of Foundation classes to allow easy implementation of GUI-s (Graphical User Interface) For this lecture borrowed heavily from: Top-Level Containers Applet Dialog Frame

UniS 4 Swing Basics General-Purpose Containers Panel Scroll pane Split pane Tabbed pane Tool bar

UniS 5 Swing Basics Special-Purpose Containers Internal frame Layered pane Root pane

UniS 6 Swing Basics Basic Controls Buttons Combo box List Menu Slider Spinner Text field or Formatted text field Text fieldFormatted text field

UniS 7 Swing Basics Uneditable Information Displays Label Progress bar Tool tip

UniS 8 Swing Basics Interactive Displays of Highly Formatted Information Color chooser File chooser Table Text Tree

UniS 9 The JComponent Class java.lang.Objectjava.awt.Component java.awt.Container javax.swing.JComponent java.awt.Window java.awt.Frame javax.swing.JFrame javax.swing.JLabel javax.swing.JToolbar javax.swing.JPopupMenu javax.swing.JFileChooser javax.swing.JTextArea

UniS 10 Swing Basics: Course Case Study JTextAreaJTextField JToolBar JPopupMenu JFrame

UniS 11 Swing Basics: Course Case Study ImageIconJLabelJFileChooser

UniS 12 Swing Basics To make any graphic program work we must be able to create windows and add content to them. To make this happen we must: Import the pertinent packages. Set up a top-level container. Display the container. Be thread-safe.

UniS 13 Swing Basics Import the pertinent packages. import javax.swing.*; Set up a top-level container. JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("HelloWorldSwing"); Display the container. frame.pack(); frame.setVisible(true);

UniS 14 Swing Basics Be thread-safe. public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { createAndShowGUI(); } } ); }; Swing event-handling and painting code executes in a single thread, called the event-dispatching thread. invokeLater adds a new thread to be executed by the event dispatcher.

UniS 15 Swing Basics: Hello World Example JFrame JLabel String used in constructor method for JLabel Exit program on close

UniS 16 import javax.swing.*; public class HelloWorldSwing { private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String display_string = “Some Text” JLabel label = new JLabel(display_string); frame.getContentPane().add(label); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); }}); }}

UniS 17 HelloWorldSwing JLabel label = new JLabel(display_string); frame.getContentPane().add(label); JLabel label = new JLabel(display_string); java.awt.Container frameCt = frame.getContentPane(); frameCt.add(label); Strange Part of Code Is equivalent to these two lines

UniS 18 Sequence Diagram for HelloWorldSwing :HelloWorldSwing :Event Dispatcherframe:JFrame label:JLabel frameCt :Container createAndShowGUI > setDefaultCloseOperation > getContentPane add(label) pack setVisible(true)

UniS 19 HelloWorldString Variable Scope Trying to access variables declared inside createAndShowGUI outside of the definition is illegal. E.g: public class HelloWorldSwing { private static void createAndShowGUI() { JFrame frame = new JFrame("HelloWorldSwing"); } java.awt.Container ct = frame.getContentPane(); public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } $ javac HelloWorldSwing.java HelloWorldSwing.java:29: cannot resolve symbol symbol : variable frame location: class HelloWorldSwing java.awt.Container ct = frame.getContentPane(); ^ 1 error

UniS 20 String Handling in HelloWorldSwing static String display_string = " Hello World "+ " This is an example of a"+ " JFrame Swing Object. "+ "A JFrame "+ " by itself does not provide any "+ "functionality. "+ "Even the text in the content pane of this"+ " JFrame "+ "is constructed by a JLabel object."+ " ";

UniS 21 String Handling in HelloWorldSwing String simpleString = "this" + "and" "that"; Is the same as: String simpleString = "thisandthat"; To get spaces would write: String simpleString = "this " + "and " + "that ";

UniS 22 String Handling in HelloWorldSwing Can add formatting such as new line `\n' and tabs `\t' String simpleString = "\nNewLine\twith tabs" Some swing components (such as JLabel) can interpret some HTML String simpleString = " Hello World "; Note this is not always true.

UniS 23

UniS 24