同样代码大量精简 <span style="font-size:14px;">import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; import java.awt.event.WindowListener ; import java.awt.event.WindowAdapter ; import java.awt.event.WindowEvent ; import java.awt.event.KeyEvent ; import java.awt.event.MouseEvent ; import java.awt.event.MouseAdapter ; import java.awt.event.KeyAdapter ; import java.awt.event.KeyListener ; import java.awt.event.MouseListener ; import javax.swing.JTextArea ; import javax.swing.JFrame ; import javax.swing.JScrollPane ; import javax.swing.JPasswordField ; class MyMouse extends JFrame { JTextArea text = new JTextArea() ; public MyMouse() { super.setTitle("鼠标精灵") ; JScrollPane scr = new JScrollPane(text) ; scr.setBounds(5,5,300,200) ; super.add(scr) ; text.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { text.append("鼠标被按下 ") ; } }) ; super.addWindowListener(new WindowAdapter() { public void WindowClosing(WindowEvent e) { System.exit(1) ; } }) ; super.setSize(400,300) ; super.setVisible(true) ; } } ; class Tester { public static void main(String args[]) { MyMouse mhk = new MyMouse() ; } } ; </span>