Monday, 16 December 2013

Graphic java course, Drawing in Applet [ Part 8 ]


Paint Application

This Tutorial help you to make a paint application


Source code



       

package javacourse;//Your package name

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

public class Paint2 extends Applet implements MouseMotionListener
{
Graphics ge;
Image backbuffer;
int x,y;
public void init()
{
backbuffer = createImage( 1500, 1500 );
ge = backbuffer.getGraphics();
addMouseMotionListener(this);
}
@Override
public void mouseDragged(MouseEvent e) {
x=e.getX();
y=e.getY();
ge.fillOval(x, y, 4, 4);
repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
x=e.getX();
y=e.getY();
}
public void update( Graphics g ) {
g.drawImage( backbuffer, 0, 0, this );
}
}
        
    


0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes