📄 guithread.java
字号:
import java.awt.*;
import java.awt.event.*;
public class GuiThread
{
public static void main(String args[]) throws Exception
{
Frame f=new Frame();
Button b=new Button("Press me");
myListener m=new myListener();
b.addActionListener(m);
f.add(b,"Center");
f.setSize(100,60);
f.setVisible(true);
f.addWindowListener(m);
myThread.view();
}
}
class myListener extends WindowAdapter implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
myThread.view();
}
public void windowClosing(WindowEvent we)
{
myThread.view();
System.exit(0);
}
}
class myThread{
public static void view()
{
Thread t=Thread.currentThread();
System.out.println("当前线程:"+t.getName());
int n=Thread.activeCount();
System.out.println("活动线程个数:"+n);
Thread threads[]=new Thread[n];
t.enumerate(threads);// 枚举数组
for(Thread thread:threads)
{
String s=thread.isDaemon()?"后台线程":"前台线程";
System.out.println(s+":"+thread.getName());
}
System.out.println("---------------------");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -