mouseListeners

i am writing mouselestener program like thise

import java.awt.*; import java.awt.event.*; class WindowClosing3 extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } } class MouseEventSample1 extends Frame implements MouseListener,MouseMotionListener { int x1,x2,y1,y2;
public MouseEventSample1() { setVisible(true); Dimension d=new Dimension(); d.height=650; d.width=1000; setSize(d); setResizable(false); //setBackground(); Font f1=new Font("",Font.BOLD,50); addWindowListener(new WindowClosing3() ); addMouseListener(this); addMouseMotionListener(this);

  }
 public void mouseMoved(MouseEvent me)
  {

  }
 public void mouseDragged(MouseEvent me)
  {
  }

 public void mouseEntered(MouseEvent me)
  {
  }
 public void mouseExited(MouseEvent me)
  {
  }
  public void mousePressed(MouseEvent me)
  {
  }
  public void mouseReleased(MouseEvent me)
  {
  }
 public void mouseClicked(MouseEvent me)
  {
    System.out.println("mouseclicked");
  }

} class MouseEventSample { public static void main(String ar[]) { Frame f=new MouseEventSample1(); }

} when i clicked on the output window the message "mouseclicked" not printed.please give me solution

View Answers

July 19, 2011 at 10:33 AM

Here the message "mouse clicked" is printed on the console through your code. Save the java file with the name MouseEventSample. And if you want to display the message on dialog box, then use the following instead of System.out.println();

JOptionPane.showMessageDialog(null,"mouse clicked");









Related Tutorials/Questions & Answers: