import javax.swing.*;
import java.awt.event.*;//事件处理类
//符合标准,实现了接口ActionListener
//包含有方法actionPerformed()
public class DMLst implements ActionListener,Runnable
{
JFrame frm;
JPanel p; JButton btn; public void run()
{
int k=1;
while(k<=20)
{
System.out.println(k);
k++;
}
} public DMLst()
{
frm=new JFrame();
p=new JPanel(); btn=new JButton("OK"); //btn.addActionListener(new DMLst());
btn.addActionListener(this);
//this相当于是new DMLst(),指当前类的对象
p.add(btn); frm.getContentPane().add(p);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(300,300);
frm.setVisible(true);
} public static void main(String args[])
{
new DMLst();
}
public void actionPerformed(ActionEvent evt)
{
System.out.println("ABCDEFG"); //Thread th=new Thread(new DMLst());
Thread th=new Thread(this);
th.start(); System.out.println("123456"); Thread xx=new Thread(this);
xx.start(); System.out.println("The END.");
}
}
import java.awt.event.*;//事件处理类
//符合标准,实现了接口ActionListener
//包含有方法actionPerformed()
public class DMLst implements ActionListener,Runnable
{
JFrame frm;
JPanel p; JButton btn; public void run()
{
int k=1;
while(k<=20)
{
System.out.println(k);
k++;
}
} public DMLst()
{
frm=new JFrame();
p=new JPanel(); btn=new JButton("OK"); //btn.addActionListener(new DMLst());
btn.addActionListener(this);
//this相当于是new DMLst(),指当前类的对象
p.add(btn); frm.getContentPane().add(p);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(300,300);
frm.setVisible(true);
} public static void main(String args[])
{
new DMLst();
}
public void actionPerformed(ActionEvent evt)
{
System.out.println("ABCDEFG"); //Thread th=new Thread(new DMLst());
Thread th=new Thread(this);
th.start(); System.out.println("123456"); Thread xx=new Thread(this);
xx.start(); System.out.println("The END.");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货