201521123087 Java Programming 6th Week of study summary

Source: Internet
Author: User

1. Summary of this Week's study

2. written work
  1. Clone method
    1.1 Object in thecloneMethod is modified by protected, What do you need to be aware of when overriding the Clone method in your custom class? Answer: with PR otected modification, It can only be accessed by classes and subclasses within the same package, and it is possible to change protected to use public declaration to increase the scope of cloning.
    1.2 When you design your own class, what kind of method is generally used to modify the protected? To workShapeFor illustrative Examples. A: For methods that only want to access the class and subclass of the same package, use Prote CTED Decoration.
    The shape class, whose subclasses have Circle, rectangle,circle, and Rectangle inherit the shape class, so have getperimeter and Getarea respectively to calculate area and Perimeter.
    1.3 Write simple in the Test1 packageEmployeeclass, create a new one in the Test2 packageTestProtectedclass, and in main, try to invoke the Clone method of the employee in the Test1 package to clone a new object, can it be successful? A: Must not be, first, not in the same package, followed by special Text2 package testprotected class does not have Implements.

  2. Overriding a topic with an anonymous class and a lambda expression object-oriented 2-advanced-the problem of the inner class of a polymorphic interface 5-2
    Just paste the key code and run the results, the picture is not too large.                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp               Answer:

    •   NameComparator a = new NameComparator();Arrays.sort(persons,a);for(PersonSortable2 personSortable2 : persons){ System.out.println(personSortable2);}AgeComparator b = new AgeComparator();Arrays.sort(persons,b);for(PersonSortable2 personSortable2 : persons){ System.out.println(personSortable2);}
    • Lamda-expression

       arrays.sort ( Span class= "hljs-selector-tag" >persons, (o1,o2) Span class= "hljs-selector-tag" >->o1.compareto (o2.getname ())); arrays.sort ( persons, (o1,o2) ->o1-o2.getage ();      

    Experimental results:                               &NBS P                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                                                           ,         &NB sp; 

  3. Analyze the following code to answer shapeComparator what does the object pointed to have to do with the comparator interface?

    Comparator<Shape> shapeComparator = new  Comparator<Shape>() {       @Override       public int compare(Shape o1, Shape o2) { //你的代码 } }; 答:shapeComparator实现Comparator接口。
  4. Event handling in the GUI
    4.1 Write out the most important keywords in the event-handling model. Answer: Event source, Event object, Listener.
    4.2 Use code and annotations to prove that you understand the event-handling model. For:

    •  PublicClassEventMainGUI1Extendsframe{Staticint count=1;PublicEventMainGUI1(String Title) {Super (title); }PublicStaticvoidMain(String Args[]) {EventMainGUI1 f=New EventMainGUI1 ("hello"); F.setlayout (New FlowLayout ());final JButton b = new JButton ( "1"); //event source, Create a button B.addactionlistener (new actionlistener () { Span class= "hljs-function" >public void actionperformed (actionevent evt) {b.setlabel (new Integer (++count). toString ()); //every click of the button, the number on the button will be added 1}); F.add (b); //add button f.setsize (100,200); //set form size F.setbackground (color.pink); //set the form color f.setvisible (true); //set form visible}}            
  5. Pair programming: object-oriented Design (big job 2-very important, unfinished-2)
    Continue to refine last Week's project Assignments. The assessment points are as follows:
    5.1 Try overwriting using the graphical interface.
    5.2 Gives a record of the same item on the code cloud for two People.
    5.3 What are the major changes to the project compared to last week?

Resources:
Pair programming Reference
Drawing with ProcessOn
Video-writing a GUI with NetBeans
Important: Swing Experimental Reference
JTable usage, for rendering tabular data
Swing related articles

3. Code submission record on code Cloud and PTA Experiment Summary

Topic set: jmu-java-04-object-oriented 2-advanced-polymorphic Interface Inner class

3.1. Code cloud codes submission record
    • In the code cloud project, Select Statistics-commits history-set time period, and then search for and
3.2. PTA Lab                                                          ,         &N Bsp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NBsp                           A: 1. The first problem is to use the array to implement the function of the stack, define the implementation class arrayintegerstack of the interface, and determine the stack into the STACK. It's a bit difficult, and it's constantly being perfected.
2. Creation of a static inner class that establishes another class in one class.

201521123087 Java Programming 6th Week of study 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.