0% found this document useful (0 votes)
2 views

java program

This Java applet program creates a simple drawing application where users can draw by dragging the mouse. It initializes an image and sets up a mouse motion listener to capture drag events, allowing users to draw circles on the applet. The drawing is done in blue on a white background, and the applet is designed to be displayed in a specified width and height.

Uploaded by

Vali Bhasha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java program

This Java applet program creates a simple drawing application where users can draw by dragging the mouse. It initializes an image and sets up a mouse motion listener to capture drag events, allowing users to draw circles on the applet. The drawing is done in blue on a white background, and the applet is designed to be displayed in a specified width and height.

Uploaded by

Vali Bhasha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

13a

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//<applet code="paintdemo" width="800" height="500"></applet>
public class paintdemo extends Applet implements MouseMotionListener
{
int w, h;
Image i;
Graphics g1;
public void init()
{
w = getSize().width; h = getSize().height;
i = createImage( w, h );
g1 = i.getGraphics();
g1.setColor( Color.white ); g1.fillRect( 0, 0, w, h ); g1.setColor( Color.red );
i = createImage( w, h );
g1 = i.getGraphics();
g1.setColor( Color.white ); g1.fillRect( 0, 0, w, h ); g1.setColor( Color.blue );
addMouseMotionListener( this );
}
public void mouseMoved( MouseEvent e ) { }
public void mouseDragged( MouseEvent me )
{
int x = me.getX(); int y = me.getY();
g1.fillOval(x-10,y-10,20,20);
repaint();
me.consume();
}
public void update( Graphics g )
{
g.drawImage( i, 0, 0, this );
}
public void paint( Graphics g )
{
update(g);
}
}
Output:

You might also like