JAVA为何鼠标事件没响应

importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassJButtonExample... import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class JButtonExample implements ActionListener, MouseListener {
JFrame f;

JButton b;

JTextField t,t1;

int tag = 0;

public static void main(String[] args) {
JButtonExample tb = new JButtonExample();
tb.go();

}

public void go() {

JFrame f = new JFrame("button");
Container content = f.getContentPane();
JButton b = new JButton("sample");
b.addActionListener(this);
content.add(b, "South");
t = new JTextField();
t1 = new JTextField();
content.add(t, "Center");
content.add(t1, "North");
f.addMouseListener(this);
// String s="press the button";
// t.setText(s);
f.setSize(300, 300);
f.setVisible(true);

}

public void actionPerformed(ActionEvent e) {
String s1 = "press the button";
String s2 = "press ";
if (tag == 0) {
t.setText(s1);
tag = 1;
} else {
t.setText(s2);
tag = 0;
}
}

public void mouseClicked(MouseEvent e) {
String s3 = "button";
//t.setText(s3);
System.out.println("enter");
}

public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
String s2 = "press ";
t1.setText(s2);
}

public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

}
展开
 我来答
flyingFish211
2012-06-05 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
修改
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class JButtonExample implements ActionListener, MouseListener {
JFrame f;

JButton b;

JTextField t, t1;

int tag = 0;

public static void main(String[] args) {
JButtonExample tb = new JButtonExample();
tb.go();

}

public void go() {

JFrame f = new JFrame("button");
Container content = f.getContentPane();
JButton b = new JButton("sample");
b.addActionListener(this);
content.add(b, "South");
t = new JTextField();
t1 = new JTextField();
content.add(t, "Center");
content.add(t1, "North");
b.addMouseListener(this);
// String s="press the button";
// t.setText(s);
f.setSize(300, 300);
f.setVisible(true);

}

public void actionPerformed(ActionEvent e) {
String s1 = "press the button";
String s2 = "press ";
if (tag == 0) {
t.setText(s1);
tag = 1;
} else {
t.setText(s2);
tag = 0;
}
}

public void mouseClicked(MouseEvent e) {
String s3 = "button";
t1.setText(s3);
System.out.println("enter");
}

public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
String s2 = "press ";
t1.setText(s2);
}

public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

}
追问
你的改的哪里哦,我怎么看不出来有什么不同呢
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友399369b
2012-06-05
知道答主
回答量:3
采纳率:0%
帮助的人:4777
展开全部
路过、、、
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式