Copyright © 1999-2011 Curt Hill More Widgets In Abstract Window Toolbox.

Slides:



Advertisements
Similar presentations
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
More on GUI We wrap up our examination of Java GUI programming by looking at several other components and their listeners – The components all come from.
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
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.
Components. Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent –TextArea –TextField.
CS102--Object Oriented Programming Lecture 19: – The Swing Package (II) Copyright © 2008 Xiaoyan Li.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L04 (Chapter 15) Creating.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
12-Jul-15 Components. 2 Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent TextArea TextField.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CST JavaScript Validating Form Data with JavaScript.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
6 Copyright © 2004, Oracle. All rights reserved. Working with Data Blocks and Frames.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
GUI Programming in Java: Event Handling & More Components Corresponds with Chapter 14, Chapter 15.
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.
Aligning the data in cells By default, Excel aligns text entries on the left margin of the cell (left justification) and aligns numeric entries on the.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
Dale Roberts GUI Programming using Java - GUI Components Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
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.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CHAPTER:07 JAVA IDE PROGRAMMING-II Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Getting Input. Text Fields A text field is a box that the user can type in Use the JTextField class JTextField tf1 = new JTextField(15); 15 is the field.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
AWT Package. Java GUI classes are contained in the java.awt package. Java GUI classes are contained in the java.awt package. A graphical Java program.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Software Construction LAB 08 Java Programming with SWING GUI Builder.
CSI 3125, Preliminaries, page 1 AWT Control. CSI 3125, Preliminaries, page 2 AWT Control The AWT supports the following types of controls: ■ Labels ■
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.
Unit 3: Text, Fields & Tables DT2510: Advanced CAD Methods.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
Chapter 3: Widgets for a GUI General Component methods Useful widgets classes –Text classes Label TextField TextArea –Active widgets Button Checkbox Choice.
AWT AWT stands for Abstract Windowing Toolkit. It contains all classes to write the program that interface between the user and different windowing toolkits.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
HTML Again GUI Items Originally HTML 4 Copyright © Curt Hill.
Chapter 5 Validating Form Data with JavaScript
A First Look at GUI Applications Radio Buttons and Check Boxes
Java GUI.
Objectives Design a form Create a form Create text fields
Graphical User Interface (pronounced "gooey")
Chap 7. Building Java Graphical User Interfaces
Chapter 13: Advanced GUIs and Graphics
Graphical User Interfaces -- Introduction
Chapter 7 Creating User Interfaces
AWT Components and Containers
Chapter 17 Creating User Interfaces
Chapter 17 Creating User Interfaces
Advanced GUIs and Graphics
Presentation transcript:

Copyright © Curt Hill More Widgets In Abstract Window Toolbox

Copyright © Curt Hill AWT Widgets Widget can be: –Button –Label –Text Field –Text Area –Check boxes –Radio buttons –Lists –Scroll Bars

Copyright © Curt Hill TextArea or JTextArea A multi-line edit box May have scrollbars May specify the visible number of rows and columns Methods and events similar to TextField

Copyright © Curt Hill TextArea Constructors TextArea() TextArea(String) // initial contents TextArea(String,int,int) // plus size TextArea(int,int) TextArea(String,int,int,int) // scrollbars

TextArea Manipulation Main methods are: setText(String) –Sets entire contents getText() –Returns a string append(String) –Adds to the end of contents –No newline is appended Copyright © Curt Hill

Escape Sequence Since append will not automatically send contents to a new line, this must be done with an escape sequence An escape sequence is a means to display characters not normally displayable Two character representation for a single actual character Prefixed with a backslash Copyright © Curt Hill

Escape Characters \n – newline \t – tab \” – double quote \’ – apostrophe \\ - the slash itself Copyright © Curt Hill

Check Boxes Class is Checkbox or JCheckBox Three constructors: –Checkbox() –Checkbox(String) - (the label of the check box) –Checkbox(String, boolean) - (label and initial value) Checkbox: –getState returns the value –setLabel changes the label JCheckBox: –isSelected returns the value –setText changes the label

Copyright © Curt Hill Check Box Listener ItemListener itemStateChanged(ItemEvent) is the function Called whenever state changes Both Checkbox or JCheckBox

Copyright © Curt Hill Radio Buttons AWT did not have one A radio button is any check box that is part of a CheckboxGroup Same action listener –Although changing one clears another, need one for each button Same methods Different constructors

Copyright © Curt Hill Constructors Three parameters in two orders: –String, boolean, CheckboxGroup –String, CheckboxGroup, boolean –String is label –boolean is initial value –CheckboxGroup is the grouping box

Copyright © Curt Hill CheckboxGroup Similar to a predefined event handler Only one check box can be on in any CheckboxGroup Not a GUI, Widget or descendent of Component –No physical or display representation –The radio buttons do not have to be near each other

Copyright © Curt Hill Checkboxes Two additional methods: Allows dynamic adding / changing of CheckboxGroups setCheckboxGroup(CheckboxGroup ) –If null is passed it is no longer part of a check box –There can be initial problems getCheckboxGroup()

Copyright © Curt Hill JRadioButton Similar to check box in Check box group –However, it is its own class ButtonGroup performs same function of CheckboxGroups They have a property that selects the ButtonGroup –ButtonGroup has an add method also isSelected gets the value

Radio Button Problems Radio buttons are nice for small number of choices Typically three to five Larger than that takes up too much space For larger use a List or JList Copyright © Curt Hill

Lists and JLists A list is a box displaying multiple items Three modes: –Single item can be selected –Single interval –Multiple intervals Clicking on an item selects it Similar to Radio buttons but scrollable

Copyright © Curt Hill List Constructor List() List(int rows) –Single mode List(int rows, boolean multiple)

Copyright © Curt Hill Adding and Removing add(String) –Adds the string to list box add(String, int index) –Adds the string to list box at position indicated by index –index is zero based remove(String) –removes first occurrence of String remove(int index) –removes positionally

Copyright © Curt Hill What is Selected? int getSelectedIndex() –returns -1 if zero or more than one item is selected int[] getSelectedIndexes() –returns a potentially zero length array of selected items String[] getSelectedItems() –returns an array of selected strings String getItem(int index) gets any string

Copyright © Curt Hill Other methods select(int index) –highlights a selection deselect(int index) getItemCount() getVisibleIndex() –Last item visible isIndexSelected(int index)

Copyright © Curt Hill List Listeners ActionListener –Triggered by double clicks ItemListener –When something is selected or deselected –Cursor motion or click or double click

Copyright © Curt Hill JLists Javax version of Lists Constructors: –Default –Array of Object or Vector Also uses getSelectedIndex(es) but not the getSelectedItems, instead getSelectedValue(s)

Copyright © Curt Hill Drop Down Lists Class name Choice Condense a list into one line with an activation button Current value is all that is visible No multi-selection is possible Only constructor is default

Copyright © Curt Hill Choice Methods Most of same methods as List –add –getSelectedIndex The multiples returns of List are not allowed –getSelectedIndexes Uses same listeners

Copyright © Curt Hill Scroll Bar Class name Scrollbar or JScrollBar Come automatically with some widgets, such as a list too large to fit They can be separate as well They allow a numerical value to be entered graphically Horizontal or Vertical

Copyright © Curt Hill Scroll Bar Constructors Default One parameter (HORIZONTAL or VERTICAL) Five parameter –Orientation –Initial position –Indicator size –Minimum –Maximum

Copyright © Curt Hill Scroll Bar Methods getValue –returns the integer value setValue(int) All the other values can be set or get

Copyright © Curt Hill Scroll Bar Listeners AdjustmentListener is the class adjustmentValueChanged(Adjustme ntEvent) is the method

Copyright © Curt Hill JScrollPane A container into which another component is placed Does not need the listeners like ScrollBars Has a margin and a viewport The viewport is itself a container

Copyright © Curt Hill JViewPort A JViewPort may only hold one item No real need for layout manager –Must have one because it is a container The one item may be another container such as a panel

Copyright © Curt Hill JScrollPane again Method getViewport returns the Viewport Use the viewport to add the component: x.getViewport.add(comp) –Where x is the JScrollPane and comp is the component to add

Copyright © Curt Hill JScrollPane scrollbars There are two: – horizontalScrollbar –verticalScrollbar Each of these have a policy which may be: –x_SCROLLBAR_AS_NEEDED –x_SCROLLBAR_NEVER –x_SCROLLBAR_ALWAYS The x may be: –HORIZONTAL –VERTICAL Set by setHorizontalScrollBarPolicy or setVerticalScrollBarPolicy

Copyright © Curt Hill Text There are several objects that are used for text JTextField –A control for entry of plain text JPasswordField –Single line masked text similar to JTextField JTextArea –Multiline, but still plain text JEditorPane –May edit plain text, HTML, RTF JTextPane –Derivation of JEditorPane

Copyright © Curt Hill JEditorPane Formatting and text –Allows display of text with the usual formatting Each paragraph has formatting characteristics Each paragraph is composed of sequences of formatted text This requires more set up to make a real editor

Copyright © Curt Hill Related Objects There are several objects that are used in formatted text objects Style StyledDocument EditorKit

Copyright © Curt Hill Style An interface –Derived from Attribute which contains name value pairs A collection of attributes to associate with an element in a formatted text object The implemented methods include: –addChangeListener –getChangeListener –getName

Copyright © Curt Hill Styled Document The parameter of one of the JTextPane constructors Describes formatting: –Fonts –Colors –CharacterAttributes –ParagraphAttributes

Copyright © Curt Hill EditorKit Establishes the tools needed for an editor Factory for the policies of an editor Actions –Sets the Caret –Reads and writes files into the pane Use getEditorKit to initialize

Copyright © Curt Hill JTextPane Derived from JEditorPane Two constructors –Default –StyledDocument

Conclusion Much more here that you should need for any assignment Using these widgets will allow flexible GUIs Copyright © Curt Hill