只有3会答:
javax.swing.Timer可以实现,等我打球回来详细解释。

解决方案 »

  1.   

    建立Listener监听,运行期,其实Listener可以一直处于活动状态,只是在需要状态变化时,对Listener的状态进行改变。
      

  2.   

    借个场地:)
     我的jdk路径c:\jdk1.3\bin
    我的文件路径:d:\myjava\MyFirstProgram.java//主类名也是MyFirstProgram
    在autoexec.bat里面设置了:SET CLASSPATH=d:\myjavad:\myjava>javac MyFirstProgram.java
    编译的时候为什么说读文件错误,怎么修改???????   
      

  3.   

    to:ggyy(原始社会好,原始社会好!) 
    在classpath中加一个.表示当前路径。 改为set classpath=d:\myjava;.
    以后不要占用别人的场地。:)
      

  4.   

    3 please use: Thread.sleep(interval);
    http://java.sun.com/docs/books/tutorial/post1.0/preview/threads.html
      

  5.   

    I think you may declare a public variable so that the two threads can both read data from it.
    You may need another two boolean variables for each threads to indicate that they are ready to receive or send data.
      
      

  6.   

    我的主程序是定义了两个线程,一个管接收,一个管发送这个公共变量只有在主程序中定义了,但是,但是怎么返回?线程类中的public void run()方法是引自runnable接口的,不允许有任何返回值,郁闷中!
      

  7.   

    我大概能明白你的意思,有几种方法可以,其中之一是要找到/建立2个线程
    都可以访问的一个变量,利用这个变量(再配合同步措施),可以实现2个线程
    之间的信息传递,比如:
     - 建立一个2个线程都可以访问的类,在这个类中封装一个field
     - 把产生2个线程的2个类做成另一个类的内部类,这样在2个run()中
       都可以访问这个“上级类”的field另外,run()主要不是由你调用的,所以不能/不要依靠run()来返回结果ggyy(从来没有这样冲动过,从来没有这样兴奋过),你好,嘻嘻,在建立
    环境时一般都是设"set CLASSPATH=%CLASSPATH%;.",应该是可以的,
    在NT和win98下我都是这样用的,你再试一下
      

  8.   

    1.我的网络程序中有两个线程...
    class SharedArea
    {
       public synchronized getXX();
       public synchronized setXX();
       public variables...;
    }class Thread1 implements Runnable()
    {
       setPublicAread(SharedArea area);
    }
    class Thread2 implements Runnable()
    {
       setPublicArea(SharedArea area);
    }main()
    {
       area = new PublicArea();
       thread1 = new Thread1();
       thread1.setPublicArea(area);
       thread2 = new Thread1();
       thread2.setPublicArea(area);   thread1.start();
       thread2.start();
    }
    2.还是acsII码,怎么得到数字(应该说是byte)所表示的ascII码?又如何把ascII码边成数字(byte)?   char c = 'a';
       byte b = (byte)c;
       c = (char)b;3.想每隔一段时间就启动接受线程一次,不知道这个时间控制怎么写,想弄个循环180次,每次等待1秒,这样就有了每3分钟接受一次的效果,但这个等待1秒的代码……
       Thread.sleep(1000); or you can use timer.
      

  9.   

    高手们,多谢多谢,感激不禁!那个sleep()是能在run()里面用吗
      

  10.   

    yes, you can use it anywhere.
      

  11.   

    Pipe the output of a thread to the input of other threads
    The idea is to make the READ operation ATOMIC. Once the READING is started for one thread, it cannot be interrupted by another one.    Pipeline Thread
      
          +----------+         +----------+
          | thread A |  ---- > | thread B |
          +----------+    |    +----------+
           (produce)      |     (consume)
                          | 
                          |
                          |    +----------+
                          +- > | thread C |
                               +----------+ 
                                (consume)
     
    The produceData.class and consumeData.class are the same as the previous JAVA How-to. [AtomicInputStream.java] import java.io.*;public class AtomicInputStream extends PipedInputStream {
      int atom = 0;  AtomicInputStream(int atom) {
        super();
        this.atom = atom;
        }
      public synchronized int atomicRead(byte[] x)  {
        try {
          read(x, 0, atom);
          }
        catch (Exception e) {
          e.printStackTrace();
          return -1;
          } 
        return atom;
        }
      }
     [sendProduction.java] import java.io.*;public class sendProduction extends produceData {
      OutputStream os;  sendProduction(OutputStream os) {
      super(os);
      this.os = os;
      }  public boolean dataProduction() {
        byte[] j = new byte[3];
        boolean done = false;
        j[0] = 0 ; j[1] = 1; j[2] = 2;  
        java.util.Random r = new java.util.Random();
        while(!done) {
          try {
            os.write(j, 0, 3);
            }
          catch (Exception e) { 
            e.printStackTrace();
            return true;
            }   
          }
        return done;    
        }
      }
     [receiveProduction.java] import java.io.*;public class receiveProduction extends consumeData {
      AtomicInputStream as;  receiveProduction(AtomicInputStream as) {
        super(as);
        this.as = as;
        }  public boolean dataConsumption() {
        byte [] i = new byte[3]; 
        try {
          for (;;) {
            as.read(i);
            System.out.println
              (Thread.currentThread().getName()+": " +
               i[0] + " " + i[1] + " " + i[2]);
            }
          }
        catch (Exception e) {
          e.printStackTrace();
          }
        return true;
        } 
      }
     [testThread.java] import java.io.*;public class testThread {
       public static void main(String a[]){
         try {
           PipedOutputStream os = new PipedOutputStream();
           AtomicInputStream as = new AtomicInputStream(3);
           os.connect(as);
           new sendProduction(os);
           new receiveProduction(as);       
           new receiveProduction(as);
           new receiveProduction(as);           
           }
         catch (Exception e) {
           e.printStackTrace();
           }
         }
       }
     That's OK for the situation One Producer and Many consumers. 
    To support many producers, simply create a AtomicOutputStream class with a synchronized atomicWrite method in it.