This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
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 Customer Requirements for Developers this week in the Jobs Discussion 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.
I agree. Here's the link:
subject: code not working
It's not a secret anymore!