Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes code not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "code not working" Watch "code not working" New topic

code not working

vijayalakshmi sundararajan

Joined: Dec 03, 2003
Posts: 4
I tried out this code for freehand drawing using mouse.But its not working for me.Can anyone tell me where I went wrong?
the code i hv written is as below
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Painter extends JFrame
private int xValue = -10, yValue = -10;
public Painter()
super( " Hand free drawing page ");
new Label(" Drag mouse to draw the desired picture "),
new MouseMotionAdapter()
public void mouseDragger( MouseEvent e)
xValue = e.getX();
yValue = e.getY();
public void paint( Graphics g)
public static void main(String arg[])
Painter app = new Painter();
new WindowAdapter()
public void windowClosing(WindowEvent e)
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You're painting on the JFrame itself, which is covered by the content pane. Make another component, make it listen for mouse movement and paint, and add it to the content pane.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
It is sorta covered in the JavaRanch Style Guide.
subject: code not working
jQuery in Action, 3rd edition