Christopher Budo, Davis Nygren, spencer franks, Luke miller

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Graphical User Interfaces
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Graphic User Interfaces Layout Managers Event Handling.
Graphical User Interfaces, 2D Graphics & Game Programming.
Corresponds with Chapter 12
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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.
Java Programming Chapter 10 Graphical User Interfaces.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Combo Box, Check Boxes, and Radio Buttons. Radio Buttons User can click radio buttons, just like other buttons BUT Radio buttons are mutually exclusive.
Using Inheritance to Customize Frames Use inheritance for complex frames to make programs easier to understand Design a subclass of JFrame Store the components.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
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.
Chapters (ArrayList / Generic)
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
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 Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
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.
CSE 501N Fall ‘09 18: Java GUI (Swing) 10 November 2009 Nick Leidenfrost.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
University of Limerick1 Software Architecture Java Layout Managers.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Creating a Window. A basic window in Java is represented by an object of the class Window in the package java.awt.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Computer Science [3] Java Programming II - Laboratory Course Lab 4 -1 : Introduction to Graphical user interface GUI Components Faculty of Engineering.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Java Layouts CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-3 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
1 Lecture 8: User Interface Components with Swing.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Chapter 9: Graphical User Interfaces
GUI Programming using NetBeans
Modern Programming Language Java
Graphical User Interface (pronounced "gooey")
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Timer class and inner classes
Creating Graphical User Interfaces
Graphical User Interface
Chapter 7-3 (Book Chapter 14)
Advanced GUIs and Graphics
Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Christopher Budo, Davis Nygren, spencer franks, Luke miller Advanced GUI’s Christopher Budo, Davis Nygren, spencer franks, Luke miller

Goals Familiarization with common interface components Text components Radio buttons Check boxes Menus Understand the use of layout managers to arrange user-interface components Build programs that handle events from user-interface components

Hierarchy of Swing User-Interface Components Big Java 4th Edition Chapter 18 Figure 2

Processing Text Input JTextField JTextArea

JTextFields When you use a JTextField you must give the field a width, or approximation of how many letters the user will type If a user types more characters than accounted for in the width, some characters will become invisible When using a JTextField the user can be told what to type by using a JLabel - a component that holds a string such as “Name: “ telling the user to put a name in the text field A text field fires an action when the enter key is pressed, but can be accessed without the enter key being pressed JTextField textField = new JTextField(FIELD_WIDTH);

JTextArea Holds multiple lines of text When defining an area you must supply the number of rows and columns. JTextArea textArea = new JTextArea(ROWS, COLUMNS);

Methods setText: sets the text of a text field or area textField.setText(“HI”); append: adds text to the end of a text area Note: this only works for a JTextArea not a JTextField textArea.append(account.getBalance() + "\n"); setEditable: enables or disables the user from entering text in a field or area textArea.setEditable(false);

Layout Managers In java you create user interfaces by adding components into containers such as panels Each container has its own layout manager which determines how the components are laid out. Some major layout managers FlowLayout BorderLayout GridLayout

FlowLayout Flow Layout arranges its components from left to right and starts a new row when there is no more room in the current row. Flow layout is the default layout of JPanel

BorderLayout Groups components into five areas Center North South East West Not all of the areas must be occupied Default layout for a frame

GridLayout Big Java 4th Edition Chapter 18 Figure 4 Arranges components in a grid with a fixed number of rows and columns Resizes each of the components so that they have the same size Expands each component to fill the entire area Sample code: JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(4, 3)); buttonPanel.add(button7); buttonPanel.add(button8); buttonPanel.add(button9); buttonPanel.add(button4); … Big Java 4th Edition Chapter 18 Figure 4

Nesting Panels By default, panels don’t have visible borders so you can use as many panels as you need to organize your components. You can mix together layouts by adding new panels into a larger panel such as adding a GridLayout to the center of a BorderLayout Sample code: JPanel keypadPanel = new JPanel(); keypadPanel.setLayout(new BorderLayout()); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(4, 3)); keypadPanel.add(buttonPanel, BorderLayout.CENTER); JTextField display = new JTextField(); keypadPanel.add(display, BorderLayout.NORTH);

Giving the User Choices Radio Buttons Check Boxes Combo Boxes

Radio Buttons If the choices are mutually exclusive you can use a set of radio buttons When one button is selected all other buttons of the set are turned off To create a set of radio buttons create each button individually and then add all buttons of the set to a ButtonGroup object The Button Group does not place all buttons close to eachother, it only determines which buttons should be turned on or off The isSelected() method is called to determine whether or not a button is currently selected.

Using Multiple Groups If you have multiple button groups it is a good idea to group them together visually to do so you can put each group into a panel and add a border to the panel to make it visible You can also add a title to the border Sample code: JPanel panel = new JPanel(); panel.setBorder(new EtchedBorder()); panel.setBorder(new TitledBorder(new EtchedBorder(), "Size"));

Check Boxes A check box has two states checked and unchecked You can use check boxes for choices that are not exclusive. These are implemented separately unlike radio buttons Constructing a check box: JCheckBox italicCheckBox = new JCheckBox("Italic");

Combo Boxes If you have a large number of choices radio buttons become impractical due to their size. A solution to this problem is the combo box, a combination of a text field and a list When you click on the arrow to the right of the text field of a combo box a list of selections drops down and you can choose one of the items in the list If the combo box is editable you can also type in your own selection You can get the item that the user selected by using the getSelectedItem method which will return a object.

Menus Menu Bar Menu Menu Items Menu Bar Menu Sub-menu Menu Item Big Java 4th Edition Chapter 18 Figure 12

Menu Bar The top-level container of menus Contains the “File”, ”Edit” ,”View” menus common in programs To keep the code readable, it is suggested to use different methods to construct each part of the JMenuBar.

Menu JMenus contain JMenuItems and more JMenus (submenus) JMenus do not create ActionEvents When a use clicks on a menu name, and a submenu opens, no ActionEvent is created

Menu Items A JMenuItem is at the end of a menu/submenu. JMenuItems do create ActionEvents when the user clicks on them

Sources Cay Horstmann, Big Java 4th Edition