今天在写一个用共享变量中止进程,共享变量可以变,但进程中止不了,请各们指点一下,谢谢了。附源码
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){
urltest Myurltest=new urltest();
if (e.getSource()==StartBtton){
try{
Myurltest.start();
}
catch(Exception ee){
System.out.println("Damn"+ee);
}
}
if(e.getSource()==StopButton){
try{
//urltest Myurltest2=new urltest();
Myurltest.setisStop();
//System.out.println(Myurltest.isStop);
}
catch(Exception ee){
System.out.println("Damn"+ee);
}
}
} public static void main(String[] args){
DgLib MyLib=new DgLib();
MyLib.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
};
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){
urltest Myurltest=new urltest();
if (e.getSource()==StartBtton){
try{
Myurltest.start();
}
catch(Exception ee){
System.out.println("Damn"+ee);
}
}
if(e.getSource()==StopButton){
try{
//urltest Myurltest2=new urltest();
Myurltest.setisStop();
//System.out.println(Myurltest.isStop);
}
catch(Exception ee){
System.out.println("Damn"+ee);
}
}
} public static void main(String[] args){
DgLib MyLib=new DgLib();
MyLib.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
};
解决方案 »
- LINUX 下运行Tomcat出错,命令出现乱码
- 请问各位高手,java有没有类似codeproject的网站
- 菜鸟提问:什么是VO、BO、DAO、DO?
- 如何用ANTLR来从Java源文件中获得一个class/interface的全部field或method的名字?
- 高手速看!!! 高手的高分!
- 请问各位兄弟姐妹《Java 经典实例 》在那里有免费下载啊
- java sdk最新版在哪里下载?在线等待
- 在XP中MySQL老是启动不了,怎么办呢?
- 因本人要买奔腾4电脑,故甩卖原来的电脑,整机零件都可以,各位请报价格,合适就拿走!
- java中如何检索指定路径下包含特定字符的所有字文件夹和文件
- 小问题?谢谢
- JCreator Pro 的问题
这句:urltest Myurltest=new urltest(); 转移到DgLib的成员变量那里