2016.03.13 Summary

Source: Internet
Author: User

15 Chapter Set Frame

1. Characteristics of the collection: the element type can be different, the length is variable, the space size is indeterminate.
2. Main collection classifications in JCF (Java collection Framwork): List,set,map;list and set are sub-interfaces of the collection interface, which are parallel to MAP.
3. List interface: Data elements can be duplicated, and elements are indexed in the order they are inserted.
Common Implementation classes: ArrayList: Useful for finding elements, and inefficient when adding deleted elements. LinkedList: For adding deleted elements, finding elements is inefficient.
Common methods: Get () Gets the element, set () setting element, remove () delete element, add () followed by adding element, size () collection.
4. Set interface: Data elements are not repeatable and elements are unordered.
Common Implementation classes: HashSet: fast, not sorted. TreeSet: Slow, sort. Linkedhashset: An ordered set that is optimized for set and inserted sequentially when inserting elements.
Common methods: Remove () delete element, add () add element, size () collection.
5. Generics: Because the elements are encapsulated into the collection, the specific type is hidden, to manipulate the concrete elements must be strong, and the element type inconsistency is prone to confusion, there is a high likelihood of an exception, so when the collection declaration with generics, the collection is unified into one type of data. such as:list<string> ls = new arraylist<string> (); "<String>" is a generic expression.
6. Map interface: is an unordered set consisting of key/value pairs; both key and value can be arbitrary data types, but there cannot be duplicate key values in the collection, and value values can be duplicated.
Common Implementation classes: HashMap: fast, not sorted. TreeMap: Slow, sort. Linkedhashmap: Ordered, the elements are inserted sequentially.
Common methods: Put (k,v) insert element; get (k) Gets the element Value;keyset () takes all the keys in the map out to form a set;values () fetches all value to return a set; remove (k) deletes the element.
7. Collections,arrays Tool Class: Collections is used to manipulate the set of tool classes, with more, arrays is used to manipulate the array of tool classes, with less.
The sort method in collections can set the order by overriding the Compare () method by using the comparator comparison interface, or by applying a comparable interface to the class that needs to be sorted, and overriding the CompareTo () method to set the order of arrangement. (When overridden, return-1 is the current element, 1 is the last, and 0 is not)

15 Chapter Set (2)

1. Iterator iterator: Used to traverse the collection, the efficiency is higher than for each. The main methods are Hasnext () and Next (), respectively, to determine if there is a next element, and to get the next element.
2. Set and list get the appropriate iterator by using the. Iterator () method and return a iterator.
3. The map collection does not have a direct iterator () method and must be obtained by using. EntrySet () to get a set set that contains k/v mappings, the return type of the collection is entry (internal interface of the map). The iterator is then obtained through the set's iterator () method to traverse the entry collection, and then the. GetKey () and GetValue () are used for each entry object to obtain the corresponding key and value values. The code example is as follows:

Map
map<string, integer> map = new hashmap<string, integer> ();
Map.put ("A", 1);
Map.put ("B", 2);
Map.put ("C", 3);
Map.put ("D", 4);

Convert a map's key-value mapping to a set set using EntrySet
Set<map.entry<string, integer>> set = Map.entryset ();

Call set's iterator method to get its iterator
iterator<map.entry<string, integer>> mapiter = Set.iterator ();

while (Mapiter.hasnext ()) {
Next gets a entry object, not a direct key and value.
map.entry<string, integer> Entry = Mapiter.next ();

String key = Entry.getkey ();
Integer val = Entry.getvalue ();
System.out.println ("key:" + key + "\ T" + "value:" + val);
}

16th Chapter GUI (01)

1. Singleton: You can only create a class of an object, you cannot call its construction, and a global static object is generated by means of a method. For example: public class single{
private static Single instance;
Private single () {}
Public synchronized single getinstance () {
if (this.instance = = null) {
This.instance = new single ();
}
return this.instance;
}
}

2. The GUI is divided into first-level containers: Jframe,jwindow and JDialog are used for loading other containers and components, and the components are placed in the content panel of the first container (Container) obtained through the container's static method Getcontentpane (). The component is added by container's add (component) method before it can be displayed in the First Layer container page.

3. GUI program writing steps:
A. Create a container:
Create a new container class by customizing a class to inherit the first-level container such as JFrame, and set the caption (Settitle ()), Size (SetSize ()), Render (setvisible () This step at the end), add components, and so on.
B. Building components:
Common components are: jlable (text), JTextField (input box), JPasswordField (Password input box), JTextArea (text field), Jradiobutton (single bar, general with Buttongroup use), Jcheckbox (check bar), JComboBox (drop-down menu, create object Shishun with string[]), JButton (button). Set the component position and size through setborders (), set the font style size by SetFont (new Font ()), and use SetBorder (Borderfactory.xxx ()) to set the border style. This is set by invoking the methods in the tool class Borderfactory, as described in the JDK API.
C. Adding a build to a container:
Get container: Container content = This (JFrame object). Getcontentpane (); and add by Content.add (Component).
D. Setting the layout:
Set by Setborders (), SetFont (New Font ()), SetBorder (Borderfactory.xxx ()), and so on.
E. Set the event.
PS: Dynamic and static distinction: whether there is interaction, there is interaction to become dynamic.

2016.03.13 Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.