201874040116- Li Xin "object-oriented programming (java)" twelfth week learning summary

 

 

content

This work belongs courses

https://www.cnblogs.com/nwnu-daizh/

Where this requirement in the job

https://www.cnblogs.com/nwnu-daizh/p/11867214.html

Job learning objectives

(1) master Vetor, Stack, Hashtable three classes of common use and the API;

(2) master ArrayList, LinkList two classes of common use and the API;

(3) a set of java understood framework composition;

(4) to grasp the Java GUI framework to create and property of the commonly used class of API;

(5) understand the Java GUI 2D graphics rendering commonly used class of API;

 

The first part: Summary Chapter IX, Chapter X of theoretical knowledge

  Chapter nine:

    1.java Collections Framework

      1) Java frame set includes two types of containers, one is a collection (Collection), a storage element in the set, the other is a view (the Map), stores key / value mapping. Collection connector and a 3 seed types, List, Set and Queue, and then the following are some of the abstract class, and finally the implementation class, commonly used ArrayList, LinkedList, HashSet, LinkedHashSet, HashMap, LinkedHashMap and so on.

      2) set the frame is used to represent and manipulate a set of unified architecture. Set of all frameworks comprising the following:

      • Interface: a collection of abstract data type represents. For example Collection, List, Set, Map and so on. The reason why the definition of a plurality of interfaces, is a collection of objects in order to operate in a different manner

      • Implement (s): it is a concrete implementation of a set of interfaces. Essentially, they are reusable data structure, for example: ArrayList, LinkedList, HashSet, HashMap .

      • Algorithms: Some useful computational objects that implement collection interfaces in the method of execution, such as: searching and sorting. These algorithms are referred to as polymorphism, it is because the same can have different method implemented on a similar interface.

      3) collection class is the basic interface Collection interface. The interface has a method of adding elements and add a return method implements Iterator Iterator interface objects.

      4) iterator: Iterator interface contains methods to make it have the function through the collection element. The compiler will translate into circulation for each loop with iterators.

      5) Generic Practical Method: As Collection and Iterator interfaces are generic, any practical method can be written collection type.

    2. Specific collection

      1) chain (linked list): each object is stored in a separate node, and each node also holds a reference to the next node. java, all the lists are actually doubly linked list.

      2) array list (ArrayList): implements the List interface. It encapsulates an array of a dynamic reallocation of the object.

      3) Set the hash (hash collection): can quickly find the object needed by each object has a unique hash code.

      4) Set the tree: add elements slowly, quickly find elements.

      5) with a double-ended queue Queue: allows people to effectively add and remove elements while at the head and tail.

      6) priority queue (priority queue): element may be inserted in any order, but to retrieve sorted order. It uses the heap (heap).

   3. Mapping (map)

      Mapping used to store key / value pairs. You will be able to quickly find key values.

  chapter Ten:

      AWT (Abstract Window Toolkit): Abstract Window Toolkit. GUI library for a basic program.

      Swing AWT-based powerful user interface components.

      AWT and Swing the mix can cause problems.

    1. Create a frame (frame)

      1) Frame Class (AWT) and JFrame class (the Swing) is used to describe the frame.

      2) setVisible method frame is displayed frame.

      3) positioning the frame

        1. setLocation location and method for setting the frame setBounds

        2. setIconImage used to tell which icon is displayed in the title bar of the window system, such as task switching window position.

        3. setTitle used to change the title bar text.

        4. setResizable boolean value is determined by using a frame size of the user is allowed to change.

      

  Part II: Experimental part

    

Experiment 1 :

Test Procedure 1 :

 

import java.util.Vector;
class Cat {
     private int catNumber;
     Cat(int i) {
        catNumber = i;
    }
     void print() {
        System.out.println("Cat #" + catNumber);
     }
}
public class Cats{
public static void main(String[] args){
       Vector <Cat> cats = new new Vector <Cat> (); // build stored Cat Vector collection class object cats 
       for ( int I = 0; I <. 7; I ++)                 // To set the seven elements added cats 
           cats. the addElement ( new new Cat (I));     
        for ( int I = 0; I <cats.size (); I ++)         // allow each object in the set of cats calls the print method 
           (cats.elementAt (i)) print ( . );
   }
}

 

import java.util.*;
public class Stacks
{
   static String [] = {months "gold", "silver", "copper", "iron"};         // static array of strings months 
   public  static  void main (String [] args) {        
      Stack <String> STK = new new Stack <String> ();         // build object is stored as a string of stack STK 
      for ( int I = 0; I <months.length; I ++ )
          stk.push (months [I]);                         // the elements in the stack months 
      System.out.println (stk);                         // print all of the elements stk 
      System.out.println ( "element 2 =" + stk. elementAt (2)); // print the number of elements in the stack stk 2 of 
      the while (! stk.empty ())
          System.out.println (stk.pop ());             // print elements according to the stack order 
  }
}

 

 

import java.util.*;
class Counter {
    int i = 1;
    public String toString() {
        return Integer.toString(i);
    }
}

public class Statistics {
    public static void main(String[] args) {
        Hashtable ht = new Hashtable();                
        for (int i = 0; i < 10000; i++) {
            R & lt Integer = new new Integer (( int ) (Math.random () * 20 is)); // generates a random number of 0 to 19. 
IF (ht.containsKey (R & lt))                                             // number of number of occurrences of each record 
              ((Counter ) ht.get (R & lt)) ++ I. ;
           the else 
              ht.put (R & lt, new new Counter ());
}
        System.out.println(ht);
    }
}

Test Procedure 2 :

  

Experiment 2 :

 

Test Procedure 1 :

 

Test Procedure 2 :

 

Test Procedure 3 :

 

 

 Experimental Summary:

  A collection so that we can more easily process the data, the image programming so that we can make a beautiful interface, but the actual need to do that more practice and learning.

 

 

 

              

 

Guess you like

Origin www.cnblogs.com/whitepaint/p/11872125.html