有关于GUI页面制作的问题

AI生产力实战 AI生产力实战 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我打了一段代码,不知道为什么监听器不管用,,,,在线等!!

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();
}

}



...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
AI生产力实战
Java 51,407 成员 86,130 内容