201521123117 Java Programming 6th Week of study summary

Source: Internet
Author: User
Tags event listener object object

1. Summary of this week's study

2. Written work

Q1.clone method

The methods in the 1.Object object clone are protected decorated, what do you need to be aware of when overriding the Clone method in your custom class?

A: It is important to be aware of overriding the Clone method in a custom class: First, it is clear that the Clone method of the object class is usually used to get a copy of the objects. The Clone method in object objects is protected decorated, and in order for other classes to invoke the Clone () method of the Clone class, we should set the Clone () method's property to public after overloading.

2. When you design a class, what kind of method is generally used to modify the protected? Take the job Shape as an example to illustrate.

A: In the job shape, the call perimeter and area are in the same package, not the inner class

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

A: Not successful. When calling a method, it is not in the same package, and if you want to implement the call, the package should be called first.

Q2. Overriding a set with an anonymous class and lambda expression object-oriented 2-advanced-multi-state interface The topic of the inner class 5-2
Just paste the key code and run the results, the picture is not too large.

For:

The result of the operation is:

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

A: Shapecomparator comparator's Compare method with an anonymous inner class, which enables the comparator interface and can be sorted using Arrays.sort.

Q4. Event handling in the GUI

1. Write down some of the most important keywords in the event-handling model.

A: Event source-event-event listener, such as button component JButton, container component JPanel.

2. Use code and annotations to prove that you understand the event-handling model.

For:

Import java.awt.event.*;

Import javax.swing.*;

Public class Tester {

Public static void main(string[] args) {

JFrame f = new JFrame ("Test");

       f.setdefaultcloseoperation (jframe.exit_on_close);

       jbutton b = new JButton ( "press me!"); /* here defines an event, the event source */

       b.addactionlistener (new Buttonhandler ()); /* Insert a listener */

       f.add (b); F.setsize (200, 100); F.setvisible (true);

}

3. Experimental summary

A: 5-3 should pay attention to empty stack and stack full judgment, otherwise it will be wrong.

5-4 to create a static inner class, it is also critical to find the maximum and minimum values.

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