Graphical User Interface (GUI)

Similar documents
Graphical User Interface (GUI)

Introduction to the JAVA UI classes Advanced HCI IAT351

Containers and Components

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Graphic User Interfaces. - GUI concepts - Swing - AWT

CS 251 Intermediate Programming GUIs: Components and Layout

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

encompass a group of features for building Graphical User Interfaces (GUI).

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Java Swing Introduction

Graphical User Interfaces. Comp 152

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

Graphical User Interface (GUI)

Layout. Dynamic layout, Swing and general layout strategies

Event Driven Programming

Graphical User Interfaces

Lecture 9. Lecture

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Laying Out Components. What is Widget Layout?

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Graphical User Interfaces. Swing. Jose Jesus García Rueda

FirstSwingFrame.java Page 1 of 1

Part I: Learn Common Graphics Components

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Chapter 6: Graphical User Interfaces

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

Part 3: Graphical User Interface (GUI) & Java Applets

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Java: Graphical User Interfaces (GUI)

2IS45 Programming

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Unit 6: Graphical User Interface

Chapter 12 GUI Basics

WIMP Elements. GUI goo. What is WIMP?

Java Programming Lecture 6

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Graphical User Interface (GUI)

Lecture 18 Java Graphics and GUIs

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Top-Level Containers

Java IDE Programming-I

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Using NetBeans IDE for Desktop Development. Geertjan Wielenga

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Summary Chapter 25 GUI Components: Part 2

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

More Swing. Chapter 14. Chapter 14 1

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Programming graphics

CS 2113 Software Engineering

First Name: AITI 2004: Exam 2 July 19, 2004

Systems Programming Graphical User Interfaces

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Final Examination Semester 2 / Year 2010

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Swing. By Iqtidar Ali

INTRODUCTION TO (GUIS)

Building Graphical User Interfaces. Overview

BASICS OF GRAPHICAL APPS

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

1. Swing Note: Most of the stuff stolen from or from the jdk documentation. Most programs are modified or written by me. This section explains the

CSE 331 Software Design & Implementation

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Section Basic graphics

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

1005ICT Object Oriented Programming Lecture Notes

Chapter 14. More Swing

JFrame In Swing, a JFrame is similar to a window in your operating system

Graphical User Interfaces 2

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

First Name: AITI 2004: Exam 2 July 19, 2004

Building Graphical User Interfaces. GUI Principles

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

CSE 331 Software Design & Implementation

No SVN checkout today. Object-Oriented Design

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Packages: Putting Classes Together

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Human-Computer Interaction IS4300

PIC 20A GUI with swing

Layout. Dynamic layout Layout design pattern Layout strategies

Swing: Building GUIs in Java

Final Examination Semester 2 / Year 2011

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

Human-Computer Interaction IS4300

Transcription:

Graphical User Interface (GUI) Layout Managment 1

Hello World Often have a static method: createandshowgui() Invoked by main calling invokelater private static void createandshowgui() { } JFrame frame = new JFrame("HelloWorldSwing"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(new JLabel("Hello World")); frame.pack(); frame.setvisible(true); 2

Problem GUI has lots of parts Making a GUI easy to use requires logical layout But screens should be dynamic and resizable! How do you manage layout of components? 3

Swing Components A rectangular part of a GUI window Swing Simple Components JLabel to contain output text JTextArea to allow user to type text JButton - Implements a push-button JRadioButton or JCheckButton JProgressBar JFileChooser Typically we start with one of these and extend it 4

Collect multiple Components in Container Most often, JPanel (or Jframe.contentPanel()) Use a panel for a section of the GUI Add a component to a container with the add method add(component,layout_hints) Each container has a Layout Manager Determines where to put the components in the container Invoked when Container is first built Invoked when Container is re-sized May request components to resize Default Layout Manager for JPanel is FlowLayout 5

Flow Layout Manager Like writing or reading English Components appear in the order they are added Left to right until you get to the right margin Components assume their natural (preferred) sizes Default gap between components is 5 pixels How wide is the enclosing panel? Then go to a new line 6

Box Layout Single row or column of components When creating layout, specify BoxLayout.X_AXIS or BoxLayout.Y_AXIS When creating, you have to specify container as an argument (different from other layouts) Components appear in the order they are added 7

Border Layout Specify position when adding components When resizing Center expands both x and y page_start/end expands x, line start/end expands y By default, there is a 5 pixel gap between components It s surprising how much this handles 8

Grid Layout Useful when components are in a grid Specify rows/cols as argument to constructor 0 indicates as many as needed All components same size Resized to fit container 9

GridBag Layout Extends the Grid concept by allowing components to span multiple rows/cols Each row and column can have different size Flexible and adaptable Requires the most code Specify constraints when adding components Constraints define grid coordinates of upper left corner and things like padding, grid width, grid height, etc. See the GridBagContraints class for more details 10

Card Layout Use when you want multiple versions of the display Each version is on it s own card a new Jpanel Each card can have its own layout manager You specify which card is currently displayed Similar to a tabbed windows (JTabbedPane) 11

Component Resizing It is possible to set a minimum, preferred, and maximum size on each component yellowlabel.setpreferredsize(new Dimension(200, 180)); yellowlabel.setminimumsize(new Dimension(100,20)); yellowlabel.setmaximumsize(new Dimension(600,800)); It would be nice if the layout managers all respected these constraints (they don t but some, like GridBagLayout, do) 12

Java Layout Tutorial See https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html 13

Adding Borders Every component can have its own borders Borders are created by the BorderFactory class see https://docs.oracle.com/javase/tutorial/uiswing/components/bo rder.html for some examples 14

Popup Dialogs There is a JDialog class for creating custom dialogs, but Simple popup messages are just JOptionPane.showMessageDialog(this,"Amount not recognized."); 15