Upload
everett-fox
View
212
Download
0
Embed Size (px)
Citation preview
CIS3931 - Intro to JAVA
Lecture Notes Set 7
7-June-05
Maps
• Maps create a way of storing a value that is accessed via a key (mapping a value to a key)
• Keys are unique in maps. There can not be two keys with the same name.
• Each key maps to one value.
• Values are not unique. Multiple keys may have the same value.
Creating a Map
• Map map = new TreeMap();– This creates a Map of type TreeMap
• Map map = new HashMap();– This creates a Map of type HashMap
• Etc …
Map methods
• clear() – Removes all mappings from a map
• remove(Object key) – Removes the key and associated value from the map
• put (Object key, Object value) – Associates the specified value with the specified key
• putAll(Map t) – Copies all of the mappings from the specified map to this map.
Map methods (cont.)
• containsKey(Object key) – Returns true if the maps contains a mapping for the specified key
• containsValue(Object value) – Returns true if this map maps one or more keys to the specified value
• get(Object key) – Returns the value to which this map maps the specified key.c
Map Example
• See MapExample.java
• For more information, see page 942 of your textbook.
Pattern
• Pattern creates a pattern recognizer using a regular expression
• Regular expressions info : http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
Pattern
• To create a pattern– Pattern pattern = Pattern.compile(REGEX);
– Where REGEX is a regular expression
• Example : – Pattern pattern = Pattern.compile(“\\b[a-zA-Z]+\\b”);
– Creates a pattern that will match all words with letters A-Z and a-z.
Matcher
• Uses pattern to grab all the matches out of a string
• Usage : – Matcher matcher = pattern.matcher(STRING);
Matcher - Methods
• You will find the following methods useful when writing Assignment 3…
• find() – attempts to find the next subsequence of the input sequence that matches the pattern.
• group() – Returns the input subsequence matched by the previous match.
Matcher Example
• From previously taught class : – regular_expressions.html
• See PatternMatcherExample.java
Program 2
• Example of finished source code for Program 2…
Program 3
• Posted on the Assignment page…
GUI – The Graphical User Interface
• Read Chapter 11 of the textbook !!!
• GUI’s will not be on the first midterm. However, they will be on the second midterm and final. Information from Chap. 11 may be in midterm 2 and the final.
GUI Components
• Buttons• Menus• Title Bars• Menu Bars• Combo Boxes• Scroll Bars• Panels• …etc
A Simple GUI Example
• GUI based I/O using the JOptionPane
• See GUIAddition.java
Questions?