日期:2014-05-20  浏览次数:20712 次

【急,在线等】一个中止线程的问题....
今天在写一个用共享变量中止进程,共享变量可以变,但进程中止不了,请各们指点一下,谢谢了。附源码
import   java.awt.*;
import   java.awt.event.*;
import   javax.swing.*;
import   javax.swing.event.*;
import   java.util.*;
import   java.io.*;
import   java.sql.*;  
import   java.net.*;
import   java.net.URL;
import   java.net.URLConnection;
import   java.io.IOException;
import   java.util.Date;
import   java.lang.*;
import   java.util.Timer;

class   urltest   extends   Thread{  
public   boolean   isStop=true;
public   void   run(){
    while(isStop){
            try{
      //System.out.println( "Body: "+isStop);
              String   url= "http://localhost/javasp/index.asp?name=wxf888&pass=eeee ";
      URL   Url1=new   URL(url);
      URLConnection   URLconnection=Url1.openConnection();
      URLconnection.connect();
      System.out.println( "内容类型 "+URLconnection.getContentType());
      }
      catch(IOException   e){
      System.out.println(e);
      }
      try{
      sleep(1000);
      }
      catch(InterruptedException   e){
      System.out.println(e);
      }
    }
}
public   void   setisStop(){
              isStop=false;
}
}

public   class   DgLib   extends   JFrame   implements   ActionListener
{
            private   JTextField   MoJtf=new   JTextField( "上 ");
    private   JTextField   MtJtf=new   JTextField( "下 ");
    private   JLabel   MoJLbl=new   JLabel( "上 ");
    private   JLabel   MtJLbl=new   JLabel( "下 ");
    private   JButton   StartBtton=new   JButton( "开始 ");
    private   JButton   StopButton=new   JButton( "停止 ");
            private   Container   container;

            public   DgLib(){
                  StartBtton.addActionListener(this);
  StopButton.addActionListener(this);
  JPanel   jp=new   JPanel();
  jp.setLayout(new   FlowLayout());

  jp.add(MoJLbl);
  jp.add(MoJtf);
  jp.add(MtJLbl);
  jp.add(MtJtf);
                          jp.add(StartBtton);
  jp.add(StopButton);
                          /*this.addWindowListener(
  new   WindowAdapter(){
  public   void   windowClosing(WindowEvent   e){System.exit(0);}
  });*/
  container=getContentPane();
  container.add(jp);
  this.setSize(300,100);
  this.setVisible(true);
    }

    public   void   actionPerformed(ActionEvent   e){