A little mood, before writing the Java Knot class examination

Source: Internet
Author: User
Tags final sleep thread

Suddenly found, has been a long time did not come up to write a blog, originally thought to be able to write every day, and later found that the heart is more than the strength of AH. Semester into the middle, schoolwork slowly, a variety of things are coming. This semester's Java class has also been closed, 8 weeks 32 hours, time passed quickly. Some time ago I was here to tell about their Java learning process, and now have to face the exam. Of course, I'm not afraid of exams.

My homework, finished, all written by myself, I feel very relieved. Around the problem also began to become more slowly, is the same knowledge, there are 5 days to test, everyone is trying to review. I am very grateful to ask my students questions, from their problems, I found a lot of their own shortcomings, found a lot of their own vague concept of the place, these are the best review before the exam. So, I always answer their questions patiently. At the same time, I also free of all my homework to provide to the students in need. I know, some students are not interested in this, as I am not interested in physics, but we still have to face the exam. Therefore, I try to write the notes in detail, so that they can read, the examination is open, they can also take reference. If you can use it, you must look at your own good fortune. In fact, I said the truth.

The motivation of learning is only two kinds, one is pressure, the other is interest. 8 weeks 32 hours, 8 time to remove the machine, only 24 hour. One day! To learn Java at home? No way! So there can only be pressure, to test, have to learn, to do the project, have to learn, to work, have to learn. However, I still like to start with the interest. Many of the college students like to play games, computer Science College computer penetration is quite impressive, but just playing games, it is a bit wasteful. I also like games, but basically not addictive. Have free time, I will and dormitory classmate play CS, or C&c zerohour (hehe, this game I am a master!) , or the Three Kingdoms are unique, but the time to study or study. The game should not overdo, some students around because of the game and degenerate, although I am an outsider, but sometimes still want to pull them. In fact, I think it is a good thing if I can be interested in the interior of the game world. I want to say is the game programming.

It is estimated that some people have heard Robocode, this is an IBM Alphaworks support project, is a semi-finished robot battle platform. Because after 51 to participate in the school organized robot competition, so recently solved some of the situation. I think that if you have a certain understanding of Java, and learned some basic knowledge, Robocode can improve your interest in Java learning well. Short code, clear structure, but it contains a wealth of knowledge, including mathematical knowledge, strategic knowledge, programming knowledge ... A bit deeper, you can see how the Robocode platform structure is, or try to decompile, look at the source code, which is very helpful for learning.

Oh, a bit far away, in fact, the intention of writing today is ' empty ', originally the afternoon is the first section of Java, this time is the noon break, but since there is no class in the afternoon, on the way to write their own mood, think of the place with the pen, there is no chapter, no organized, do not know whether you are satisfied. Later, will often come up here to write articles. A few weeks ago, want to write some tutorials to send up, but when pen-writing, only to find their own skills limited, it is estimated to have seen the Bruceeckel of the book for the sake of a rigorous habit, then also embarrassed to poison the masses here.

Finally, the source code to come up, is one of my Java homework, hehe, only as a memorial to the knot lesson.

* * Created on 2005-4-14 * window is divided into two areas, running two threads, one in the above area to display the * from right to left to swim the string, another in the following area from left to right the string. */

/** * Author: Long * College: School of Computer and Information technology * class: Jiko 0308 * *

Import Java.awt.*;import Java.util.*;import javax.swing.*;

Class Moveframe extends JFrame {

Private static final long serialversionuid = 1L;

Private JPanel JP1 = new JPanel (), JP2 = new JPanel ();  /** * Defines two internal classes of canvas.  * The beginning of the use of panel, found that after the painting will leave traces, * after each painting to erase, very uncomfortable, so switch to canvas, hehe. **/private Canvas cv1 = new Canvas () {private static final long serialversionuid = 1L;

int x = 0, y = MaxX = 640, MinX = 0;

Boolean isToEnd1 = false;  The algorithm that comes back when you bump into the edge is very simple.    public void Paint (Graphics g) {if (!istoend1) {g.drawstring ("Move Right", X, y);    x + 10;   if (x >= maxX) IsToEnd1 = true;    else {g.drawstring ("Move left", X, y);    x = 10;   if (x <= MinX) IsToEnd1 = false; }}, Cv2 = new Canvas () {private static final long serialversionuid = 1L;

int x = 640, y = N, MaxX = 640, MinX = 0;

Boolean isToEnd2 = false;

public void Paint (Graphics g) {if (!istoend2) {g.drawstring ("Move left", X, y);    x = 10;   if (x <= minX) IsToEnd2 = true;    else {g.drawstring ("Move Right", X, y);    x + 10;   if (x >= MaxX) IsToEnd2 = false; }  } };

private int x1 = 0, x2 = 0;

Private Thread T1, T2; Define two random variables to keep them dormant for a different time private Random rand1 = new Random ();

Private Random Rand2 = new Random ();

private void Move1 () {t1 = new Thread () {public void run () {while (true) {cv1.repaint ();     X1 = rand1.nextint (100);     try {sleep (x1);     catch (Interruptedexception e) {e.printstacktrace ();  }    }   }  }; T1.start (); }

private void Move2 () {t2 = new Thread () {public void run () {while (true) {cv2.repaint ();     x2 = rand2.nextint (100);     try {sleep (x2);     catch (Interruptedexception e) {e.printstacktrace ();  }    }   }  }; T2.start (); }

Public Moveframe () {Container CP = Getcontentpane ();  Cp.setlayout (New GridLayout (2, 1));  Cp.add (CV1);  Cp.add (CV2);  Move1 ();  Move2 ();  This.settitle ("Thread Job");  This.pack ();  This.setsize (640, 280); This.setvisible (TRUE); }}

public class Movingstring {

public static void Main (string[] args) {moveframe MF = new Moveframe ();}


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.