1 Java Swing - Lecture 2 Components and Containment Boriana Koleva

Slides:



Advertisements
Similar presentations
Components and Containers
Advertisements

Introduction to Java 2 Programming
Layered Panes Manages the painting of components to simulate different depths. The highest depth level number is on top. Components at the same depth level.
Building Applications Dialogs Passing data between windows Validating Input using FocusListeners.
Introduction to JFC Swing Written by Adam Carmi. Agenda About JFC and Swing Pluggable Look and Feel Swing Components Borders Layout Management Events.
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)
Understanding SWING Architecture CS 4170 UI Design Hrvoje Benko Oct. 9, 2001.
Object-Oriented Software Engineering Java with added Swing.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
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.
Java Swing - Lecture 1 An Introduction Milena Radenkovic slides originally by Chris Coleman.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
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.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
DAT602 Database Application Development Lecture 6 JAVA Swing.
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.
1 Java Swing - Components and Containment. 2 Components and Containers Components and Containers Components Components The building blocksThe building.
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.
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.
Oct 071 Example Program DemoLookAndFeel.java Metal (java) Motif Windows.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
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.
SWING IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
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.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Java Programming: Advanced Topics 1 Components and Facilities for Rich Graphical User Interfaces Chapter 7.
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.
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.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
University of Limerick1 Software Architecture Java Layout Managers.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
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.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Java Swing One of the most important features of Java is its ability to draw graphics.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
Getting Started with GUI Programming Chapter 10 CSCI 1302.
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:
Introduction to Swing Mr. Crone. What is Swing? a collection of pre-made Java classes used to create a modern graphical user interface.
Module 13: Swing API Object Oriented Programming(Java)
A Quick Java Swing Tutorial
Provision for GUIs in Java
University of Central Florida COP 3330 Object Oriented Programming
Java Look-and-Feel Design Guidelines
Provision for GUIs in Java
A Quick Java Swing Tutorial
Object-Oriented Software Engineering
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
Advanced Programming in Java
Presentation transcript:

1 Java Swing - Lecture 2 Components and Containment Boriana Koleva

G5BUID - Java Swing Components and Containers Components  The building blocks  Variety of uses and complexities Containers  The cement  Hierarchical organisation  Distinction is not always drawn

G5BUID - Java Swing Containment hierarchies Top level containers  Intermediate containers  Atomic components Viewing containment hierarchies 

G5BUID - Java Swing Top-level containers At the root of every containment hierarchy All Swing programs have at least one Content panes Types of top-level containers  Frames  Dialogs  Applets

G5BUID - Java Swing Frames Window with border, title and buttons Making frames  JFrame frame = new JFrame(); Or a extend JFrame class (often better code this way). Style defined with UIManager.setLookAndFeel(looknfeel); SwingUtilities.updateComponentTreeUI(frame); frame.pack();

G5BUID - Java Swing Some code! (a JFrame example) //this won’t compile… public static void main(String[] args) { JFrame frame = new JFrame(“A JFrame"); //Just like any //other class // do things with frame frame.setJMenuBar(menuBar); frame.setContentPane(contentPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set frame size frame.pack(); // realize frame frame.setVisible(true); } // end main

G5BUID - Java Swing Examples SwingApplication.java  Messy way. BetterSwingApp.java  Neater way.

G5BUID - Java Swing Dialog boxes More limited than frames Modality Types of dialogs  JOptionPane  ProgressMonitor  JColorChooser  JDialog

G5BUID - Java Swing Showing dialogs JOptionPane.showXYZDialog(…)  Option and Message dialogs  JOptionPane.showMessageDialog(frame, ”Error!”, ”An error message”, JOptionPane.ERROR_MESSAGE);  JOptionPane.showOptionDialog(frame, “Save?”, “A save dialog”, JOptionPane.YES_NO_CANCEL_OPTION);  Input, Confirm Customisation  showOptionDialog - Fairly customisable  JDialog - Totally customisable

G5BUID - Java Swing Example 3 DialogDemo.java  Not looking at code in detail…

G5BUID - Java Swing Applets Not covered in great detail here JApplet is a top-level container  has menu bar and content pane support JApplet supports assistive technologies Requires Java plug-in for browser  consider user group

G5BUID - Java Swing Intermediate containers – Panels (or ‘panes’) Root panes  The content pane  Layered panes  Glass panes

G5BUID - Java Swing Root panes ‘Invisibly’ attached to top-level container Created by Swing on realizing frame Manages everything between top-level container and components Places menu bar and content pane in an instance of JLayeredPane (see a couple of slides on)

G5BUID - Java Swing Content panes Usually use a JPanel Contains everything except menu bar for most Swing applications Can be explicitly, or implicitly created,  see (simplified) code //Create a panel and add components to it. JPanel contentPane = new JPanel(); contentPane.add(someComponent); contentPane.add(anotherComponet); //Make it the content pane. contentPane.setOpaque(true); topLevelContainer.setContentPane(contentPane);

G5BUID - Java Swing Example 4 TopLevelDemo.java  Illustrates the Content Pane, and Menu Bar positioning.

G5BUID - Java Swing Layered panes Provided by root pane, but can also be created Provides depth (z-buffering) to components ‘Depth’ is specified as integer  Frame content (-30000, content pane, menu bar)  Default (0, components)  Palette (100, toolbars and palettes)  Modal (200, internal dialogs)  Popup (300, external dialogs)  Drag (400, component when dragged)

G5BUID - Java Swing Example 5 LayeredPaneDemo.java

G5BUID - Java Swing Glass panes Not structured into components  event catching  painting Used for ‘weird’ interface behavior, rarely used. Either created explicitly or root version used

G5BUID - Java Swing Example 6 GlassPaneDemo.java

G5BUID - Java Swing Components Content of your interface  nents/components.html Created just like any class instance  JButton button_ok = new JButton(“OK”); Range in complexity from very simple (e.g. JButton) to very detailed (e.g. JColorChooser)

G5BUID - Java Swing Swing and AWT components - a quick reminder Mix Swing and AWT components as little as possible (not at all in most cases) Put ‘J’ in front of everything AWT provides to get Swing’s counterpart  AWT: Button  Swing: JButton

G5BUID - Java Swing Atomic components (1) Buttons Combo boxes Lists Menus Sliders Text Fields Labels

G5BUID - Java Swing Atomic components (2) Tool tips Progress bars Colour choosers File choosers Tables Text Trees

G5BUID - Java Swing Atomic components (3) Impossible to teach the working of every type of component Very few people know it all! – Swing is HUGE. Remember to refer to:  The Java 2 API Documentation.  The Visual index to components & containers at java.sun.com:  ents.html ents.html

G5BUID - Java Swing Summary  Containers (Frames and Dialogs) Hierarchy Root Panes Layered Panes Content Panes Glass Panes  Components Lots of ‘em…  Next time Layout Management.