- import java.awt.*;
- import java.awt.event.*;
- class MouseAndKeyEvent
- {
- private Frame f;
- private Button but;
- MouseAndKeyEvent()
- {
- init();
- }
- public void init()
- {
- f=new Frame("it's 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.addMouseListener(new MouseAdapter(){
- public void mouseEntered(MouseEvent e){
- System.out.println("Mouse entered");
- }
- });//这一语句有问题,我用的是EditPlus,编译一直错误,求释疑
- public static void main(String[] args)
- {
- new MouseAndKeyEvent();
- }
- }
- 与君共勉
复制代码 |