首页
网站首页
公司简介
资讯中心
推荐内容
返回顶部
编程代码,程序实现了ZIP压缩和解压
发布时间:2020-01-05 13:33
浏览次数:

http://developer.51cto.com/art/201112/310575.htm

我是一个想学好变成的学生,老师说要多看多练,我要看什么呢,有点迷茫!老师说要多看看人家写的程序呀。一个合格的电子学生要看加写最低也的5万行代码。那谁能告诉我要怎么寻找编程代码,或者给我推荐的书呀什么的,多给我点宝贵建议呗。小妹在这不胜感激,嘻嘻,谢谢啦

import java.awt.*;
import java.awt.event.*;
public class Thread1Frame implements Runnable {
    StringBuffer buffer=new StringBuffer();
    Thread t1,t2;
    Thread1Frame() {
       t1=new  Thread(this);
       t2=new  Thread(this);
    }
    public synchronized void addChar(char c){
        if(Thread.currentThread()==t1){
            while(buffer.length()==0)
                try {
                    wait();
                }
                catch (Exception ex) {
                }
                buffer.append(c);
            
        }    
        if(Thread.currentThread()==t2){
                buffer.append(c);
                notifyAll();
        }    
        
    }
    
编程代码,程序实现了ZIP压缩和解压。    public static void main(String[] s){
        Thread1Frame hello=new Thread1Frame();
        hello.t1.start();
        hello.t2.start();
        while(hello.t1.isAlive()||hello.t2.isAlive()){}
        System.out.println(hello.buffer);
    }
    
    public void run(){
        if(Thread.currentThread()==t1){
            addChar('A');
        }
        
        if(Thread.currentThread()==t2){
            addChar('B');
        }
    }
}

import java.awt.*;
import java.awt.event.*;

 

 

public class DoubleThreadFrame extends Frame implements Runnable,ActionListener{
        Thread first,second,third;//创建两个线程
        int distance=10;
        Button redButton,greenButton,blueButton,startButton;
     public DoubleThreadFrame() {
           first=new  Thread(this); // 创建first线程,当前窗口作为该线程的目标对象  
            second=new  Thread(this);
            third=new  Thread(this);
            
            redButton=new Button();
            greenButton=new Button();
            startButton=new Button();
            blueButton=new Button();
            //设置按钮颜色
            redButton.setBackground(Color.red);
            greenButton.setBackground(Color.green);
            blueButton.setBackground(Color.BLUE);
            
            startButton=new Button("start");
            startButton.addActionListener(this);
            
            this.setLayout(null);
            this.add(redButton);
            redButton.setBounds(10,60,15,15);
          
            this.add(greenButton);
            greenButton.setBounds(100,60,15,15);
            
            this.add(blueButton);
            blueButton.setBounds(200,60,15,15);
            
            this.add(startButton);
            startButton.setBounds(10,100,30,30);
              
            this.setBounds(0,0,300,200);
            this.setVisible(true);
            this.validate();
            addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e){
                    System.exit(0);
                }
            });
     }
    
     public void actionPerformed(ActionEvent e){
         try {
             first.start();
             second.start();
             third.start();
         }
         catch (Exception ex) {
         }
     }
     public void run(){
         while(true){
             if(Thread.currentThread()==third){
                 moveComponent(blueButton);
                 try {
                     Thread.sleep(10);
                 }
                 catch (Exception ex) {
                 }
             }
            
             if(Thread.currentThread()==second){
                 moveComponent(greenButton);
                 try {
                     Thread.sleep(20);
                 }
                 catch (Exception ex) {
                 }
             }
            
             if(Thread.currentThread()==first){
                 moveComponent(redButton);
                 try {
                     Thread.sleep(30);
                 }
                 catch (Exception ex) {
                 }
             }
            
            
新蒲京娱乐场777,         }        
     }
     public synchronized void moveComponent(Component b){
         if(Thread.currentThread()==first){
澳门新莆京在线娱乐,             while(!(distance>=10&&distance<=100))//距离区间
新匍京娱乐场下载,                 try {
                     wait();
                 }
                 catch (Exception ex) {
                 }
                 distance++;
                 b.setLocation(distance,60);
//System.out.println("1");
                 if(distance>=100){
                     b.setLocation(10,60);//返回起始点
                     notifyAll();
                 }
             }
            
             if(Thread.currentThread()==second){
                 while(!(distance>100&&distance<=200))//距离区间
澳门葡京网上娱乐,                 try {
                     wait();
                 }
                 catch (Exception ex) {
                 }
                 distance++;
                 b.setLocation(distance,60);
//System.out.println("2");
                 if(distance>200){
        //             distance=10;//返回原点
                     b.setLocation(100,60);//返回起始点
                     notifyAll();
                 }
             }
            
             if(Thread.currentThread()==third){
                 while(!(distance>200&&distance<=300))//距离区间
                 try {
                     wait();
                 }
                 catch (Exception ex) {
                 }
                
                 distance++;
                 b.setLocation(distance,60);
//System.out.println("3");
新京葡娱乐场官网,                 if(distance>300){
                     distance=10;//返回原点
                     b.setLocation(200,60);
                     notifyAll();
                 }
             }

友情链接: 网站地图
Copyright © 2015-2019 http://www.nflfreepicks.net. 新葡萄京娱乐场网址有限公司 版权所有