最好有个例子,谢谢哈~~~
还有我这个怎么监视器没起作用啊。。import java.awt.*;
import java.awt.event.*;public class Test {
public static void main(String args[]) {
new Win();
}
}class Win extends Frame {
Button button;
TextField textf;
TextArea texta;
MouseL ml;
Win() {
setLayout(new FlowLayout());
button = new Button("Button");
textf = new TextField(8);
texta = new TextArea();
button.addMouseListener(ml);
textf.addMouseListener(ml);
texta.addMouseListener(ml);
add(button);
add(textf);
add(texta);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
pack();
setVisible(true);
validate();
}
}class MouseL extends MouseAdapter {
Win win;
public MouseL(Win win) {
this.win = win;
}
public void mousePressed(MouseEvent e) {
/*
if(e.getSource() == win.button) {
win.texta.append("mouse clicked on Button. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
if(e.getSource() == win.textf) {
win.texta.append("mouse clicked on TextField. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
if(e.getSource() == win.texta) {
win.texta.append("mouse clicked on TextArea. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
*/
System.out.println(e.getSource());
}
}
还有我这个怎么监视器没起作用啊。。import java.awt.*;
import java.awt.event.*;public class Test {
public static void main(String args[]) {
new Win();
}
}class Win extends Frame {
Button button;
TextField textf;
TextArea texta;
MouseL ml;
Win() {
setLayout(new FlowLayout());
button = new Button("Button");
textf = new TextField(8);
texta = new TextArea();
button.addMouseListener(ml);
textf.addMouseListener(ml);
texta.addMouseListener(ml);
add(button);
add(textf);
add(texta);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
pack();
setVisible(true);
validate();
}
}class MouseL extends MouseAdapter {
Win win;
public MouseL(Win win) {
this.win = win;
}
public void mousePressed(MouseEvent e) {
/*
if(e.getSource() == win.button) {
win.texta.append("mouse clicked on Button. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
if(e.getSource() == win.textf) {
win.texta.append("mouse clicked on TextField. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
if(e.getSource() == win.texta) {
win.texta.append("mouse clicked on TextArea. Position: " + "(" + e.getX() + "," + e.getY() + ").");
}
*/
System.out.println(e.getSource());
}
}
解决方案 »
- action类从页面获得两条数据后,怎么实现打印第一条数据后等待10秒钟再打印第二条数据!!在线等...
- 救命啊!大家谁知道在JAVA中如何判断当前时间是不是整点啊!急!先谢谢了!
- java处理规则文本--大家来做题
- 有两字符串s1,s2,编写一段程序寻找它们的最大公共字符串,返回最大公共字符串的字符个数。
- 如何改变画图的坐标原点
- sqlServer驱动的问题,高分求解。
- 谁能操作文件系统类实例的所有方法和属性贡献出来?
- 谁用fop解决过pdf文件里的中文问题?在fo文件里的中文生成至pdf文件之后成了"###"码了?why?
- 请问怎么用JEditorPane控件,来显示本地的html文件。
- 软件需求分析案例文档
- ThreadLocal 与 给每个线程实例传递一个新的变量,这两种做法的区别
- 求高手解决下面这个题目?关于IO流的。
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});至于ml不起作用 ,是因为你只声明,并没有在Win的构造方法中初始化,你在addMouseListener之前加上这句:
ml = new MouseL(this);