package com.haizhitao.awt;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestButton
{
public static void main(String[] args)
{
Frame frame = new Frame("Test Button");
Button button = new Button("Press me!");
//增加事件处理器
button.addActionListener(new ButtonHandler());
frame.add(button, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String label = e.getActionCommand();
System.out.println(label);
}
}
46
最新推荐文章于 2018-10-25 21:27:48 发布