JAVA怎么实现鼠标经过事件
发布网友
发布时间:2022-05-12 08:29
我来回答
共1个回答
热心网友
时间:2024-02-20 11:54
import java.awt.event.*;
import javax.swing.*;
public class Hi extends JFrame
{
public static void main(String[] args)
{
new Hi();
}
Hi()
{
JButton b=new JButton("按钮");
JPanel p=new JPanel();
b.addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
b.setText("光标在按钮上");
}
public void mouseExited(MouseEvent e)
{
b.setText("按钮");
}
});
p.add(b);
add(p);
setSize(400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
}