日期:2014-05-19 浏览次数:20745 次
package de; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class som extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; static int i=0; JButton jb; boolean mark; public som() { Panel p = new Panel(); jb = new JButton("关"); jb.addActionListener(this); p.add(jb); add(p); this.setVisible(true); this.pack(); } public static void main(String args[]) { new som(); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==jb) { if(i%2==0) { jb.setActionCommand("开"); [color=#FF0000]jb.setText(" 关");//这里忘了改变文本值,所以你看不出效果来[/color] mark=true; //用于中止线程的run()方法 i=i+1; } else { mark = false; jb.setActionCommand("关"); [color=#FF0000]jb.setText(" 关");//这里忘了改变文本值,所以你看不出效果来[/color] i=i+1; } } } }