网友您好, 请在下方输入框内输入要搜索的题目:
本题的功能是跟踪鼠标在窗口的操作,以及在窗口的坐标,包括移进、移出、移动、单击、释放和拖曳,并将这些信息显示在窗口的文字标签上。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class java3 extends JFrame. implements MouseL- istener MouseMotionListener { private JLabel statusBar; public java3 { super("java3"); statllsBar=new TLabel; getContentPane.add(statusBar,BorderLayout. SOUTH); addMouseListener(this); addMouseMotionListener(this); setSize(275,100); show; } public void mouseClicked(MouseEvent e) { statusBar.setText("Clicked at["+e.getX+ ","+e.getY+"]"); } public void mousePressed(MouseEvent e) { statusBar.setText("Pressed at["+e.getX+ ","+e.getY+"]"); } public void mouseReleased(MouseEvent e) { statusBar.setText("Released at["+e.getX +","+e.getY+"]"); } public void mouseln(MouseEvent e) { statusBar.setText("Mouse in window"); public void mouseExited(MouseEvent e) { statusBar.setText("Mouse outside window"); } public void mouseDragged(MouseEvent e) { statusBar.setText("Dragged at["+e.getX +","+e.getY+"]"); } public void mouseMoved(MouseEvent e) { statusBar.setText("Moved at["+e.getX+ ","+e.getY+"]"); } public static void main(String args[]) { java3 app=new java3; app.addWindowListener(new WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } };
参考答案