我印象当中监听器一般都是 写成一个内部类(不知道是不是这么叫),直接写在需要监听的实例后面,但是也有其他的写法,
问:一般有几种写法,而它们有区别吗,区别在哪,谢谢
问:一般有几种写法,而它们有区别吗,区别在哪,谢谢
解决方案 »
- 求java 一个方法Struts1架构 让从数据库中输出到页面上的字符只显示一部份,剩下的用...显示,如何做呢?
- 求JAVA读取 C++ DAT文件
- 求XML达人帮忙!我有一个860MB左右的XML文件,要怎么分割它?
- 求java awt实现旋转图片的代码
- 欢迎讨论-->java多线程(优先级,依赖性,动态等结合)
- 关于创建线程的问题
- 请问那里有java手册(类似MSDN这样的帮助)!!!!
- ant高手请进,请教一下关于nested element的写法,在线等待ing
- 各位,java怎么检测一个ip(网址)可以打开?有什么函数?谢谢!
- Java mail
- 我在inin()里定义了一个Jtree,那么在1个按钮的actionPerformed里如何再给这个Jtree添加节点。
- 面试题
});
t.addActionListener(e);
ActionLitener e=new ActionListener(){};
区别嘛没感觉出来,感觉后者条理性强点吧
scanDocContentPane[k].addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
setPreferredSize(new Dimension(260,280));
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setPreferredSize(new Dimension(240,270));
}});
两个问题:1,为什么一定要写那些用不着的监听(@Override下面的)
2,那个Panel是显示图片的,我想达到这样的效果,鼠标进入Panel范围内后,Panel稍微扩大,过3秒钟变回原样,不过好像不能实现
Position: Senior Java Software Engineer
Business Unit: Famous global IT company - BAS - China - ITSEResponsibilities
Lead the development of complex software product and mobile applications.
Design layered application, including user interface, business functionality, and database access.
Work with other engineers, managers, product managers, QA, and operation teams to develop innovative solutions that meet et needs with respect to functionality, performance, scalability, and reliability while meeting realistic implementation schedules and adhering to development goals and principles.
Estimate engineering efforts, plan implementations, and rollout system changes.
Share release management duties during feature rollouts and share on-call responsibilities.
Developing, unit testing, maintenance and release of software products under Agile patterns.
Experience in developing highly scalable applications a major plus.
Job Requirements
BS/BA in CS or related field.
5+ years experience in requirements analysis, design, coding and testing of scalable, distributed, fault-tolerant applications.
Expertise required in object-oriented design methodology and enterprise application development in Java .
Hands-on experience with J2EE/J2SE application.
Hands-on experience in Agile projects.
Good at OO methodology, and familiar with Java design patterns.
Proven result-oriented person with a delivery focus in a fast pace, high quality environment.
Self-motivated and work under pressure.
Solid capabilities of self study for new technologies.
Knowledge of software product development is a major plus
Fluent English in both speaking and writing.有意者加MSN:[email protected]
1,匿名类 写法
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
public class Test {
public static void main(String args[]){
Circle c1=new Circle();
}}
class Circle extends JFrame{
int x,y;
public Circle(){
init();
this.setBounds(50,50,700,700);
this.setVisible(true);
}
public void paint(Graphics g){
g.fillOval(x,y,3,3);
}
void init(){
this.addMouseListener(new MouseAdapter(){//匿名类写法
public void mouseClicked(MouseEvent e){
x=e.getPoint().x;
y=e.getPoint().y;
repaint();
}
});
}
}
2。内部类写法
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
public class Test {
public static void main(String args[]){
Circle c1=new Circle();
}}
class Circle extends JFrame{
int x,y;
public Circle(){
init();
this.setBounds(50,50,700,700);
this.setVisible(true);
}
public void paint(Graphics g){
g.fillOval(x,y,30,30);
}
void init(){
this.addMouseListener(new Mo());//对内部类的实例化 }
class Mo extends MouseAdapter{ //内部类
public void mouseClicked(MouseEvent e){
x=e.getPoint().x;
y=e.getPoint().y;
repaint();
}
}
}
3.外部类写法
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
public class Test {
public static void main(String args[]){
Circle c1=new Circle();
}}
class Circle extends JFrame{
static int x,y;
public Circle(){
init();
this.setBounds(50,50,700,700);
this.setVisible(true);
}
public void paint(Graphics g){
g.fillOval(x,y,30,30);
}
void init(){
this.addMouseListener(new Mo(this)); //传递JFrame } }
class Mo extends MouseAdapter{ //外部类
JFrame f;
public Mo(JFrame f){
this.f=f;
}
public void mouseClicked(MouseEvent e){
Circle.x=e.getPoint().x;
Circle.y=e.getPoint().y;
f.repaint(); //强制重画
}
}
for(h = 1;h < 15;h++){
scanDocContentPane[h].addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("ASDS"+h);
TeleAScanPopFrame popFrame = new TeleAScanPopFrame(); popFrame.showPopFrame(scanDocContentPane[h].getImagePath());
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
});
}
这样的监听结果,竟然是输出ASDS15,为什么不是点击中哪个Panel显示哪个?比如点击scanDocContentPane[4]应该输出SADS4才对吧