下面这个代码不知道为什么鼠标监听器的动作实现不了。。。在线等!
package J_Fram;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class J_Frame_MouseLisenter extends MouseAdapter{
JFrame f;
JButton red,blue,yellow;
public J_Frame_MouseLisenter() {
// TODO Auto-generated constructor stub
f = new JFrame("鼠标事件");
f.setLayout(new FlowLayout());
f.setBounds(400, 200, 300, 250);
red = new JButton("红色");
red.addMouseListener(this);
f.add(red);
f.setVisible(true);
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
f.setBackground(Color.RED);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
J_Frame_MouseLisenter t= new J_Frame_MouseLisenter();
}
}