Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS3931 - Intro to JAVA Lecture Notes Set 7 7-June-05.

Similar presentations


Presentation on theme: "CIS3931 - Intro to JAVA Lecture Notes Set 7 7-June-05."— Presentation transcript:

1 CIS3931 - Intro to JAVA Lecture Notes Set 7 7-June-05

2 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.

3 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 …

4 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.

5 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

6 Map Example See MapExample.java For more information, see page 942 of your textbook.

7 Pattern Pattern creates a pattern recognizer using a regular expression Regular expressions info : http://java.sun.com/j2se/1.5.0/docs/api/jav a/util/regex/Pattern.html http://java.sun.com/j2se/1.5.0/docs/api/jav a/util/regex/Pattern.html

8 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.

9 Matcher Uses pattern to grab all the matches out of a string Usage : –Matcher matcher = pattern.matcher(STRING);

10 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.

11 Matcher Example From previously taught class : –regular_expressions.htmlregular_expressions.html See PatternMatcherExample.java

12 Program 2 Example of finished source code for Program 2…

13 Program 3 Posted on the Assignment page…

14 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.

15 GUI Components Buttons Menus Title Bars Menu Bars Combo Boxes Scroll Bars Panels …etc

16 A Simple GUI Example GUI based I/O using the JOptionPane See GUIAddition.java

17 Questions?


Download ppt "CIS3931 - Intro to JAVA Lecture Notes Set 7 7-June-05."

Similar presentations


Ads by Google