如果遇到0分的问题,你会进去看吗??

huyanqieyu 2008-03-23 10:10:34
import java.awt.Frame;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ww
{
public static void main(String[] args)
{
int i;
final Mythread m=new Mythread();
Frame f=new Frame();
f.setSize(555, 555);

f.setLayout(new GridLayout(13,5));
Button b=new Button("按钮");
Button c=new Button("按钮c");

f.add(b);
f.add(c);
f.setVisible(true);

f.addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{
m.start();
System.out.print(" end");

}
});
}
}


class Mythread extends Thread
{
public void run()
{
for(int i=0;i <12;i++)
{
try
{
Thread.sleep(332);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
if(i==4)
this.interrupt();

System.out.print(i);
}
}
}


运行结果怎么会这样;
end012345java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at Mythread.run(ww.java:52)
67891011


当i=4的时候线程不是应该中断吗,
...全文
134 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
healer_kx 2008-03-24
  • 打赏
  • 举报
回复
如果我知道你这个是问题,我就不进来了。
cryptlordx 2008-03-24
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 madfrug 的回复:]
引用 5 楼 dyy830606 的回复:
程序员貌似来这里不是为了分,多交些朋友,多学点东西最重要
[/Quote]
madfrug 2008-03-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dyy830606 的回复:]
程序员貌似来这里不是为了分,多交些朋友,多学点东西最重要
[/Quote]
高远工作室 2008-03-24
  • 打赏
  • 举报
回复
结果是这样的:end01234java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at Mythread.run(ww.java:52)
567891011
syz720 2008-03-24
  • 打赏
  • 举报
回复
(*^__^*) 嘻嘻……,人家程序捕获到异常后,打印出来
下面还有代码,当然会继续执行,我是这么认为的
3楼的代码,就捕获到异常就结束了!
zjhlht 2008-03-24
  • 打赏
  • 举报
回复
catch (InterruptedException e)
{
e.printStackTrace();
}
e.printStackTrace(); <-------那异常应该是这个的作用,如果有异常,打印出异常的信息
dyy830606 2008-03-24
  • 打赏
  • 举报
回复
程序员貌似来这里不是为了分,多交些朋友,多学点东西最重要
ninesea 2008-03-24
  • 打赏
  • 举报
回复
从来不看分多少 只看标题
ooo19841080xinxin 2008-03-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 try__again 的回复:]
我一向是看标题的
[/Quote]
wo ye shi
try__again 2008-03-23
  • 打赏
  • 举报
回复
我一向是看标题的
linmen1983 2008-03-23
  • 打赏
  • 举报
回复
import java.awt.Frame;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ww
{
public static void main(String[] args)
{
int i;
final Mythread m=new Mythread();
Frame f=new Frame();
f.setSize(555, 555);

f.setLayout(new GridLayout(13,5));
Button b=new Button("按钮");
Button c=new Button("按钮c");

f.add(b);
f.add(c);
f.setVisible(true);

f.addWindowListener(new WindowAdapter() { public void windowClosing (WindowEvent e) { m.start(); System.out.print(" end");}});
}
}


class Mythread extends Thread
{

public void run()
{
try
{
for(int i=0;i <12;i++)
{
Thread.sleep(332);
if(i==4)
this.interrupt();
System.out.print(i);
}
}catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
wyg0508 2008-03-23
  • 打赏
  • 举报
回复
会进来的,我也是没有分的人
呵呵,帮你顶一下,
还不能给你解决

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧