The message is not shown on the frame.import java.awt.Graphics; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JFrame; public class MouseEvent implements MouseListener,MouseMotionListener { static JFrame f = new JFrame(); String msg = " "; int mouseX = 0,mouseY = 0; public void init() { f.addMouseListener(this); f.addMouseMotionListener(this); } @Override public void mouseDragged(java.awt.event.MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseMoved(java.awt.event.MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(java.awt.event.MouseEvent e) { // TODO Auto-generated method stub mouseX = 0; mouseY = 10; msg = "Mouse clicked"; f.repaint(); System.out.println("Mouse clicked"); } @Override public void mouseEntered(java.awt.event.MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(java.awt.event.MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(java.awt.event.MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(java.awt.event.MouseEvent e) { // TODO Auto-generated method stub } public void repaint(Graphics g) { g.drawString(msg,mouseX,mouseY); } public static void main(String[] args) { MouseEvent me = new MouseEvent(); me.init(); f.pack(); f.setVisible(true); } }