Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 swing 程序一个。。事件为什么不发生?
develop8





发贴: 129
积分: 0
于 2006-06-23 07:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
//为什么鼠标事件不发生???
class wonder{
public static void main(String[]args){
JFrame a =new JFrame();
JTextField tf = new JTextField(10);
Container c =a.getContentPane();
c.add(tf,BorderLayout.NORTH);
a.setVisible(true);
a.setBounds(100,200,400,300);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setBackground(Color.yellow); //不起作用????
a.validate();
a.addMouseListener(new MouseAdapter(){
public void MouseIntered(MouseEvent e){
System.out.println(e.getY());
}
public void MouseClicked(MouseEvent e){
System.out.println(e.getY());}
});

}
}



作者 Re:swing 程序一个。。事件为什么不发生? [Re:develop8]
lisliefor





发贴: 287
积分: 7
于 2006-06-23 09:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
个人理解,请楼主核实:
Container可以理解为一个虚幻的、作为一些组件载体的空间,就好像一栋房子的地基。我很多时间都没用它,直接使用JFrame作为最基本的载体。它不能设置颜色,如果你像设置背景色,那么让JFrame的对象调用那个方法吧!
至于你鼠标事件没有相应,可能因为你没有写鼠标事件的其他事件,即使你不用到它们,也需要将它们列出来,方法具体实现可以为空。
鼠标事件写成适配器的形式倒没有用过,有可能上面的猜测是错误的。
一般实现MouseMotinListener或MouseListener接口,处理鼠标事件。
如果你需要例子,我倒可以免费提供。 Smile



作者 Re:swing 程序一个。。事件为什么不发生? [Re:develop8]
develop8





发贴: 129
积分: 0
于 2006-06-24 06:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好啊,什么资料??我可以看看吗


作者 Re:swing 程序一个。。事件为什么不发生? [Re:develop8]
tomcatexpert





发贴: 52
积分: 2
于 2006-06-25 22:30 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哎,这么低级的错误实在不该犯啊

a.addMouseListener(new MouseAdapter(){
public void MouseIntered(MouseEvent e){
System.out.println(e.getY());
}
public void MouseClicked(MouseEvent e){
System.out.println(e.getY());}
});

记住java程序规则是方法的第一个字母是小写,你override的方法应该是
mouseEntered
mouseClicked



作者 Re:swing 程序一个。。事件为什么不发生? [Re:develop8]
lisliefor





发贴: 287
积分: 7
于 2006-06-28 09:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
develop8 wrote:
好啊,什么资料??我可以看看吗



资料是实体书!



作者 Re:swing 程序一个。。事件为什么不发生? [Re:develop8]
develop8





发贴: 129
积分: 0
于 2006-07-02 06:26 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
tomcatexpert
哎,这么低级的错误实在不该犯啊
---------------------------------
多谢楼上的批评,
以后尽量不犯的。
以后会把方法名看清楚之后再写的。




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923