Components and Containers

Slides:



Advertisements
Similar presentations
G5BUID - Java Swing Laying out components Manage realized components Determine size and position Each container has a layout manager (usually)
Advertisements

FH-Hof Dialoge Richard Göbel. FH-Hof Inhalt JDialog Vordefinierte Dialoge File Browser.
Introduction to Java 2 Programming
User Interfaces II GUI – Awt, Swing, Web
14 Copyright © 2005, Oracle. All rights reserved. User Interface Design: Swing Basics Planning the Application Layout.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 22 GUI Programming I.
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 program.
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)
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
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.
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.
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.
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Object-Oriented Software Engineering Java with added Swing.
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction To Form Builder
Advanced Java Class GUI, part 2. JComponent methods addXXXListener(XXXListener) repaint() – [optional arguments: delay and coordinates of sub-area to.
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.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
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.
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.
Introduction to Computation and Problem Solving Class 14: Introduction to the Swing Toolkit Prof. Steven R. Lerman and Dr. V. Judson Harward 1.
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.
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.
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.
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.
University of Limerick1 Software Architecture Java Layout Managers.
Swing / Session1 / 1 of 30 Module Introduction Distributed Computing in Java.
Option Panes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Swing Components. Introduction Swing – A set of GUI classes – Part of the Java's standard library –Much better than the previous library: AWT Abstract.
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Basics of GUI Programming Chapter 11 and Chapter 22.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
1 COS 260 DAY 24 Tony Gauvin. 2 Agenda Questions? 10 th Mini Quiz Corrected –So-so results Capstone progress report over due Course evaluations Assignment.
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.
Objects First With Java A Practical Introduction Using BlueJ Building Graphical User Interfaces (GUIs) Week
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:
Module 13: Swing API Object Oriented Programming(Java)
A Quick Java Swing Tutorial
University of Central Florida COP 3330 Object Oriented Programming
Provision for GUIs in Java
Object-Oriented Software Engineering
Graphics Programming - Frames
Steps to Creating a GUI Interface
A Quick Java Swing Tutorial
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

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

Containment hierarchies Top level containers Intermediate containers Atomic components G5BUID - Java Swing - 2005

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 - 2005

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 - 2005

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 - 2005

Examples 1 + 2 SwingApplication.java BetterSwingApp.java Messy way. Neater way. G5BUID - Java Swing - 2005

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

Showing dialogs JOptionPane.showXYZDialog(…) Customisation 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 - 2005

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 - 2005

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

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