CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
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.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
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.
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.
Java Programming Chapter 10 Graphical User Interfaces.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
CSE 219 Computer Science III Graphical User Interface.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
GUI programming Graphical user interface-based programming.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
CS Lecture 01 Frames and Components and events Lynda Thomas
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
GUIs for Video Games. The Plan ● Layout suggestions ● Observer/Observable ● Steps to writing Observer/Observables ● Sample Code ● Practice.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Java's Graphical User Interface Toolkit
Layout Managers Arranges and lays out the GUI components on a container.
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.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
A simple swing example GETTING STARTED WITH WIND CHILL.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Computer Science 209 GUIs Model/View/Controller Layouts.
Java layout managers. import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public.
Basics of GUI Programming Chapter 11 and Chapter 22.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
1 Chapter 16: Creating Windows. 2 Basics of GUI Programming How to create a Window. TryWindow.java You always need a JFrame component before creating.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
CSI 3125, Preliminaries, page 1 Layout Managers. CSI 3125, Preliminaries, page 2 Layout Managers The LayoutManagers are used to arrange components in.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
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.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Dept. of CSIE, National University of Tainan 10/21/2012 Arranging Components on a User Interface.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Object-Orientated Analysis, Design and Programming
Graphical User Interfaces
Graphical User Interfaces -- GUIs
Swing JComponents.
GUIs Model/View/Controller Layouts
Ellen Walker Hiram College
Graphical user interface-based programming
Creating Graphical User Interfaces
Steps to Creating a GUI Interface
GUI building with the AWT
Graphical User Interface
Presentation transcript:

CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI

CompSci 100E 35.2 Components  JLabel text/image display  JTextField single line for text input/output  JTextArea multiple lines for text input/output  JButton used for decisions  JFrame a basic window

CompSci 100E 35.3 Components  JLabel text/image display  JTextField single line for text input/output  JTextArea multiple lines for text input/output  JButton used for decisions  JFrame a basic window

CompSci 100E 35.4 Components  JLabel text/image display  JTextField single line for text input/output  JTextArea multiple lines for text input/output  JButton used for decisions  JFrame a basic window

CompSci 100E 35.5 Flat Layouts GridLayoutBorderLayout CENTER NORTH SOUTH WEST EAST

CompSci 100E 35.6 Flat Layouts GridLayout  Added left to right, top to bottom  Expands to fill horizontally and vertically  Each space equal width and height BorderLayout  Not all positions must be filled  CENTER expands horizontally and vertically  NORTH and SOUTH expand horizontally  WEST and EAST expand vertically

CompSci 100E 35.7 Flat Layouts BorderLayout

CompSci 100E 35.8 Flat Layouts GridLayout

CompSci 100E 35.9 Hierarchical Layouts You can put layouts within layouts:

CompSci 100E Hierarchical Layouts Identify the BorderLayout and GridLayouts in the application on the right.

CompSci 100E Hierarchical Layouts CENTEREAST

CompSci 100E Hierarchical Layouts GridLayout

CompSci 100E Hierarchical Layouts GridLayout

CompSci 100E Hierarchical Layouts CENTER SOUTH

CompSci 100E Hierarchical Layouts CENTER SOUTH

CompSci 100E Hierarchical Layouts

CompSci 100E Hierarchical Layouts  Virtually every layout we make is a hierarchy of GridLayout and BorderLayout  Other Layouts include  BoxLayout  GridBagLayout  CardLayout  Or: almost no Layout  FlowLayout

CompSci 100E Designing a GUI  What components are needed?  Which components are of primary importance? Secondary?  How do the components relate to each other?  How big are the components?  How can they be arranged into BorderLayout and GridLayout?

CompSci 100E Coding a GUI 1. Declare the components as instance variables 2. Write a makeComponents method to initialize the components 3. Write a layoutComponents methods to arrange the components 4. Write a constructor to call the above two methods 5. Write a setVisible method to set the primary component’s visibility (usually a JFrame).

CompSci 100E Examples  BorderExample.java (today)  In code directory (GUIs.jar)  GridExample.java  CombinedExample.java

CompSci 100E BorderExample.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class BorderExample extends JApplet { JFrame frame; JTextArea middle; JTextField bottom; JButton left, right; JLabel title;

CompSci 100E BorderExample.java private void makeComponents() { frame=new JFrame("BorderExample"); middle=new JTextArea(10, 40); bottom=new JTextField(); left=new JButton("left"); right=new JButton("right"); title=new JLabel("Title"); }

CompSci 100E BorderExample.java private void makeLayout() { Container container=frame.getContentPane(); container.setLayout(new BorderLayout()); container.add(new JScrollPane(middle), BorderLayout.CENTER); container.add(title, BorderLayout.NORTH); container.add(left, BorderLayout.WEST); container.add(right, BorderLayout.EAST); container.add(bottom, BorderLayout.SOUTH); frame.pack(); }

CompSci 100E BorderExample.java public BorderExample() { makeComponents(); makeLayout(); } public void setVisible(boolean vis) { frame.setVisible(vis); }

CompSci 100E BorderExample.java public void init() { main(null); } public static void main(String[] args) { BorderExample example=new BorderExample(); example.setVisible(true); }

CompSci 100E Event Handling  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples  Practice

CompSci 100E Event Model AWT Event Loop Program Thread

CompSci 100E Making the GUI Interactive 1) import java.awt.event.* 2) implements ActionListener 3) write method public void actionPerformed(ActionEvent e) 4) call addActionListener(this) for all JButton s

CompSci 100E Examples AdderGUI.java GameShell.java

CompSci 100E Examples AdderGUI.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AdderGUI extends JApplet implements ActionListener

CompSci 100E Examples AdderGUI.java public void actionPerformed(ActionEvent ae) { String addend0Text=addend0.getText(); double addend0Number=Double.parseDouble(addend0Text); String addend1Text=addend1.getText(); double addend1Number=Double.parseDouble(addend1Text); double answer=addend0Number+addend1Number; sum.setText(""+answer); }

CompSci 100E Examples AdderGUI.java private void makeComponents() { frame=new JFrame("Game Shell"); addend0=new JTextField(8); addend1=new JTextField(8); sum=new JTextField(8); compute=new JButton("="); compute.addActionListener(this); plus=new JLabel("+"); plus.setHorizontalAlignment(SwingConstants.CENTER); }

CompSci 100E Examples GameShell.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GameShell extends JApplet implements ActionListener

CompSci 100E Examples GameShell.java public void actionPerformed(ActionEvent ae) { Object cause=ae.getSource(); if(cause==pause) { if(pause.getText().equals("Pause")) { pause.setText("Resume"); shell.setText("Paused"); } else { pause.setText("Pause"); shell.setText("Game Running"); } if(cause==reset) { pause.setText("Start"); shell.setText("Splash"); }

CompSci 100E Examples GameShell.java pause=new JButton("Start"); pause.addActionListener(this); reset=new JButton("Start New Game"); reset.addActionListener(this);