wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "code not working" Watch "code not working" New topic
Author

code not working

vijayalakshmi sundararajan
Greenhorn

Joined: Dec 03, 2003
Posts: 4
Hi,
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 ");
getContentPane().add(
new Label(" Drag mouse to draw the desired picture "),
BorderLayout.SOUTH);
addMouseMotionListener(
new MouseMotionAdapter()
{
public void mouseDragger( MouseEvent e)
{
xValue = e.getX();
yValue = e.getY();
repaint();
}
}
);
setSize(300,150);
show();
}
public void paint( Graphics g)
{
g.fillOval(xValue,yValue,4,4);
}
public static void main(String arg[])
{
Painter app = new Painter();
app.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
Nathan Pruett
Bartender

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code not working
 
Similar Threads
Instance Variable errors for MouseMotionAdapt
Button not appearing and drawString issue
Can't see my Panels!!! Aaarrghhhhh....
Weird error not sure what Im doing wrong
Inheritance problem