import java.awt.*;
import java.awt.event.*;
class pro extends Frame {
int a;
public static void main(String[] args) {
pro frame =new pro("pro");
}
public pro(String str) {
super(str);
setSize(500, 500);
setLayout(new FlowLayout());
Button bu1 = new Button("z1");
bu1.addActionListener(new beck());
add(bu1);
bu1.setActionCommand("c1");
Button bu2 = new Button("z2");
bu2.addActionListener(new beck());
add(bu2);
bu2.setActionCommand("c2");
setVisible(true);
addWindowListener(new stopwin());
a=0;
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
class beck implements ActionListener {
public void actionPerformed(ActionEvent e) {
if ("c1".equals(e.getActionCommand()))a=a+2 ;
if ("c2".equals(e.getActionCommand()))a=a+1;
System.out.println(a);
}
}
}
最終更新:2011年01月27日 09:04