Java中的鼠标事件,请帮我解释一下每句话

发布于2022-01-12 18:25:09

import java.awt.*;import java.awt.event.*;import java.applet.*;public class Example6_1 extends Applet implements MouseListener{TextField text;But

1个回答
admin
网友回答2022-01-12
我也是新手 看看把import java.awt.*;import java.awt.event.*;import java.applet.*;public class Example6_1 extends Applet implements MouseListener{ TextField text;Button button; TextArea textArea; public void init() { this.setSize(800, 600); text=new TextField(10); text.addMouseListener(this); button=new Button("按钮"); button.addMouseListener(this); textArea=new TextArea(); textArea.setSize(200, 100); this.addMouseListener(this); this.add(button); this.add(text); this.add(textArea); } public void moousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { if(e.getSource()==button) { textArea.append("\n在按钮上鼠标按下,位置:"+"("+e.getX()+","+e.getY()+")"); } else if(e.getSource()==text) { textArea.append("\n在文本框上鼠标按下,位置:"+e.getX()+","+e.getY()); } else if(e.getSource()==this) { textArea.append("\n在容器上鼠标按下,位置:"+e.getX()+","+e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { if(e.getClickCount()>=2) textArea.append("鼠标连击指令,位置:"+"("+e.getX()+","+e.getY()+")"); } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub }}

回到
顶部