201874040116- Li Xin "object-oriented programming (java)" Week 16 learning summary

project

content

This work belongs courses

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

Where this requirement in the job

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

Job learning objectives

          

            (1) master the Java application packaging operations;

            (2) to grasp the concept of threads;

            (3) master the two techniques threads created.

 

 

Part I: summary of the intellectual content of textbooks 14.1-14.3 (20 points)

   The ability to run multiple programs at the same moment: multitasking (multitasking)

  Program Typically, a task is called a thread (thread) can run multiple threads simultaneously is called a multi-threaded program (multithreaded). Different processes and threads.

  Thread of control classes: Thread

  Thread (Runnable target) Constructs a new thread for calling a given target run () method. 

  void sleep () method is used to pause time in milliseconds the current thread. 

  void start () to start the current thread, will lead to calls run () method.

  interrupt thread object to call interrupt the function, add the equivalent of a mark, when the thread of execution to determine whether there is a method using isInterruptted mark, there is interrupt thread, if any, continue

 

  Thread has New (newly created), Runnable (run), Blocked (blocked), Wait (wait), Timed waiting (waiting time record), Terminated (terminated) six states.

Part II: Experimental part

Experiment 1: Test Procedure 1 (10 min)

package resource;

import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;

/**
 * @version 1.41 2015-06-12
 * @author Cay Horstmann
 */
public class ResourceTest
{
   public static void main(String[] args)
   {
      EventQueue.invokeLater(() -> {
         JFrame frame = new ResourceTestFrame();
         frame.setTitle ( "ResourceTest" ); 
         frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 
         frame.setVisible ( to true ); 
      }); 
   } 
} 

/ ** 
 * a loading frame images and text resources. 
 * / 
Class ResourceTestFrame the extends the JFrame 
{ 
   Private  static  Final  int DEFAULT_WIDTH = 300 ;
    Private  static  Final  int DEFAULT_HEIGHT = 300 ; 

   public ResourceTestFrame () 
   { 
      the setSize (DEFAULT_WIDTH, DEFAULT_HEIGHT); 
      
      //Find places to find ResourceTest class about.gif file 
      the URL of aboutURL = getClass () getResource ( "about.gif." ); 
      
      // this image as a frame icon 
      Image img = new new ImageIcon (aboutURL) .getImage (); 
      the setIconImage (IMG); 

      the JTextArea the textArea = new new the JTextArea (); 
      
      // action getResourceAsStream method is to find resources and classes in the same position, returns a resource URL can be loaded or input stream 
      . InputStream stream = getClass () getResourceAsStream ( "about .txt " ); 
      
      // use the same code when reading the text. 8-UTF 
      the try (Scanner in = new new Scanner (Stream," UTF-. 8 " )) 
      { 
         the while (in.hasNext ()) 
            textArea.append (in. nextLine ()+ "\n");
      }
      add(textArea);
   }
}

 

 

Experiment 1: Test Procedure 2 (10 minutes)

 

Experiment 1: Test Procedure 3 (10 minutes)

 

Previous program only to stop the movement of the ball after a complete circle, did not appear at the same time more balls, then a program can not only stop at any time, can occur simultaneously multiple balls.

Experiment 2: Pair programming practice covers the following four parts :( the 17 weeks experimental course on-site inspection score: 30 points)

1) Description of programming ideas;

2) in line with the program code of the programming specifications;

3) program run feature Screenshots;

Experimental Summary: (15 points)

    This experiment made me understand the advantages of ways to deploy java program and basic knowledge of multi-threaded programs compared to single-threaded and multi-threaded program procedures.

Guess you like

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