if i change the value of xvalue and yvalue in the code below it changes everything on the screen even the things already painted how do i work around that?? i want to leave things already drawn untouched and just change the size of the oval on the next draw. looking for some ideas here plz.
code:
// Fig. 13.19: Painter2.java
// Using class MouseMotionAdapter.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Painter2 extends JFrame {
private int pointCount = 0;
// array of 1000 java.awt.Point references
private Point points[] = new Point[ 1000 ];
// set up GUI and register mouse event handler
public Painter2()
{
super( "A simple paint program" );
// create a label and place it in SOUTH of BorderLayout
getContentPane().add( new JLabel( "Drag the mouse to draw" ),
BorderLayout.SOUTH );
addMouseMotionListener(
new MouseMotionAdapter() { // anonymous inner class
// store drag coordinates and repaint
public void mouseDragged( MouseEvent event )
{
if ( pointCount < points.length ) {
points[ pointCount ] = event.getPoint();
++pointCount;
repaint();
}
}
} // end anonymous inner class
); // end call to addMouseMotionListener
setSize( 300, 150 );
setVisible( true );
} // end Painter2 constructor
// draw oval in a 4-by-4 bounding box at specified location on window
public void paint( Graphics g )
{
super.paint( g ); // clears drawing area
for ( int i = 0; i < points.length && points[ i ] != null; i++ )
g.fillOval( points[ i ].x, points[ i ].y, xvalue, yvalue );
}
public static void main( String args[] )
{
Painter2 application = new Painter2();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class Painter2
code:
// Fig. 13.19: Painter2.java
// Using class MouseMotionAdapter.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Painter2 extends JFrame {
private int pointCount = 0;
// array of 1000 java.awt.Point references
private Point points[] = new Point[ 1000 ];
// set up GUI and register mouse event handler
public Painter2()
{
super( "A simple paint program" );
// create a label and place it in SOUTH of BorderLayout
getContentPane().add( new JLabel( "Drag the mouse to draw" ),
BorderLayout.SOUTH );
addMouseMotionListener(
new MouseMotionAdapter() { // anonymous inner class
// store drag coordinates and repaint
public void mouseDragged( MouseEvent event )
{
if ( pointCount < points.length ) {
points[ pointCount ] = event.getPoint();
++pointCount;
repaint();
}
}
} // end anonymous inner class
); // end call to addMouseMotionListener
setSize( 300, 150 );
setVisible( true );
} // end Painter2 constructor
// draw oval in a 4-by-4 bounding box at specified location on window
public void paint( Graphics g )
{
super.paint( g ); // clears drawing area
for ( int i = 0; i < points.length && points[ i ] != null; i++ )
g.fillOval( points[ i ].x, points[ i ].y, xvalue, yvalue );
}
public static void main( String args[] )
{
Painter2 application = new Painter2();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class Painter2