import java.awt.*;
import java.awt.event.*;
class FrameDemo
{
private Frame f;
private Button but;
FrameDemo()
{
init();
}
public void init()
{
f=new Frame("my frame");
f.setBounds(300,100,600,500);
f.setLayout(new FlowLayout());
but=new Button("my button");
f.add(but);
myEvent();
f.setVisible(true);
}
private void myEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System. exit(0);
}
});
but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("action ok");
}
});
but.addMouseListener(new MouseAdapter()
{
private int count=1;
private int clickCount=1;
public void mouseEntered(MouseEvent e)
{
System.out.println("鼠标进入到该组件"+count++);
}
public void mouseClicked(MouseEvent e)
{
System.out.println("点击动作"+clickCount++);
}
});
}
public static void main(String[] args)
{
new FrameDemo();
}
}
HEI_ComeOn
相关分类