draw line,arrow,oval on the image

draw line,oval and arrow on the image dynamically.

please help.

[76 byte] By [v.kka] at [2007-11-27 11:32:45]
# 1

check API java.awt.Graphics and/or java.awt.Graphics2D, also jdk's demo programs.

always_javaa at 2007-7-29 16:47:15 > top of Java-index,Security,Cryptography...
# 2

i am tried.but not getting please help me.

v.kka at 2007-7-29 16:47:15 > top of Java-index,Security,Cryptography...
# 3

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import java.awt.image.*;

import javax.swing.*;

public class DrawOnBuffer extends JFrame

{

public static void main(String[] args) {new DrawOnBuffer();}

private BufferedImage buffer=new BufferedImage(150,150,

BufferedImage.TYPE_3BYTE_BGR);

// The shape to draw (25 is half of 50 so should be a gap of 25 on each side when the shape is drawn

private Shape toDraw=new Ellipse2D.Double(25,25,100,100);

public DrawOnBuffer()

{

this.setSize(400,400);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setVisible(true);

}

public void paint(Graphics g)

{

if (isOpaque()) { //paint background

g.setColor(getBackground());

g.fillRect(0, 0, getWidth(), getHeight());

}

// Get the graphics from the buffer (so we can draw on it)

Graphics2D bufG=(Graphics2D)buffer.getGraphics();

// Draw the circle on it in red (y not)

bufG.setPaint(Color.red);

bufG.draw(toDraw);

// Find the middle

int x=(this.getWidth()/2)-(buffer.getHeight()/2);

int y=(this.getHeight()/2)-(buffer.getHeight()/2);

// Draw the buffer to the frame (Note: using g)

g.drawImage(buffer,x,y,null);

}

}

:D

dfgstga at 2007-7-29 16:47:15 > top of Java-index,Security,Cryptography...