Line Drawing

Line Drawing

View Answers

July 15, 2008 at 4:19 PM

Hi friend,

i am sending code of draw line using java Swing

import javax.swing.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;


public class DrowLine {
public static void main(String[] args) {
System.out.println("Line draw example using java Swing");
JFrame frame = new JFrame("Draw line example");
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_BGR);
Graphics2D g = image.createGraphics();
g.setColor(Color.pink);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.BLACK);
RoundRectangle2D round = new RoundRectangle2D.Double(50, 50, 100, 100, 50, 50);
g.draw(round);
Point2D mousePoint = new Point2D.Double(101, 101);
Point2D center = new Point2D.Double(round.getCenterX(), round.getCenterY());
Point2D point2 = new Point2D.Double();
if (center.getX() == mousePoint.getX())
point2.setLocation(mousePoint.getX(), (mousePoint.getY() < center.getY()) ? round.getMinY() : round.getMaxY());
else {
double a = (center.getY() - mousePoint.getY()) / (center.getX() - mousePoint.getX());
double b = mousePoint.getY() - a * mousePoint.getX();
double x = (mousePoint.getX() < center.getX()) ? round.getMinX() : round.getMaxX();
point2.setLocation(x, a * x + b);
}
Line2D line = new Line2D.Double(mousePoint, point2);
g.setClip(round);
g.draw(line);
frame.getContentPane().add(new JLabel(new ImageIcon(image)));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}
}

-----------------------------------------

Read for more information.

http://www.roseindia.net/java/

Thanks









Related Tutorials/Questions & Answers:
Line Drawing - Swing AWT
Line Drawing  How to Draw Line using Java Swings in Graph chart,by giving x & Y axis values  Hi friend, i am sending code of draw line...) { System.out.println("Line draw example using java Swing"); JFrame frame = new
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
Advertisements
Different Line Styles
provides several line drawing attributes: the line width, the dash pattern... of the strokes of line used when drawing shapes into the image. To control the stroke width... Different Line Styles     
ModuleNotFoundError: No module named 'drawing'
ModuleNotFoundError: No module named 'drawing'  Hi, My Python... 'drawing' How to remove the ModuleNotFoundError: No module named 'drawing... to install padas library. You can install drawing python with following command
How many types of drawing objects are available in drawing toolbar
How many types of drawing objects are available in drawing toolbar  How many types of drawing objects are available in drawing toolbar
Drawing Graphs - Swing AWT
Drawing Graphs  hi i am doing a small project in java swings . there is a database table having two columns A,B i want to plot a graph to that values in database the graph must be interactive graph
Drawing Graphs - Java3D
Drawing Graphs  how to draw graphs using certain parameters  Hi Friend, To draw a graph using JfreeChart library, please visit the following link: http://www.roseindia.net/chartgraphs/index.shtml Here you
scrolling a drawing..... - Swing AWT
scrolling a drawing.....  I am using a canvas along with other components like JTable over a frame the drawing which i am going to show over canvas is dynamic and hence there is no fixed size, that's why i need to make
drawing out of bounds
drawing out of bounds  How to throw an exception when a rectangle goes out of the boundaries of a JFrame. The program is asking to draw a triangle, and resize it. If the triagle size goes out of the JFrame throw an execption. I
How to convert a picture to drawing, convert a picture to drawing, picture to drawing
How to convert a picture to drawing       Learn here a simple processing to make a color picture to drawing, we have tried here to take simple step to learn easily for the beginners
Please help in drawing Flowchart
Please help in drawing Flowchart  we found that the student names with marks in a text file the marks decreases significantly. when exams conducted fast 4 times.THe first column is the student name and the second column is marks
drawing shapes in applet - Applet
drawing shapes in applet  hi, i need a single applet prgm which draws cone,cube and square in circle.  Hi manju, This is cube example import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import
An Applet program for Drawing picture & graph - Applet
An Applet program for Drawing picture & graph  How can I write an Applet program for drawing picture and graph having various colours and tools provided
drawing a human in java - Java Beginners
drawing a human in java  i wanna to draw a human in java can u help me how can i draw.? the question is : how to draw a human in java add the nose + the eye + mouth .   where is the answer.? plz i want
ModuleNotFoundError: No module named 'jupyter-drawing-pad'
ModuleNotFoundError: No module named 'jupyter-drawing-pad'  Hi, My... named 'jupyter-drawing-pad' How to remove the ModuleNotFoundError: No module named 'jupyter-drawing-pad' error? Thanks   Hi
ModuleNotFoundError: No module named 'jupyter-drawing-pad'
ModuleNotFoundError: No module named 'jupyter-drawing-pad'  Hi, My... named 'jupyter-drawing-pad' How to remove the ModuleNotFoundError: No module named 'jupyter-drawing-pad' error? Thanks   Hi
problem in scrolling SVG drawing in canvas - MobileApplications
problem in scrolling SVG drawing in canvas  hi all, i'm developing an app that display maps on mobile -i used SVG graphics in drawing the maps... over the drawing , scrolling works well in wireless toolkit emulator , but when i
drawing a christmas tree - Java Beginners
drawing a christmas tree  how do i write a program that draws a chrimas tree using the knowledge of loops only. i.e * *** ***** ******* the program will draw a Christ mas tree  Hi ChristmasTree.javaimport java.awt.
Applet program for drawing picture and graph - Applet
Applet program for drawing picture and graph  Please send me the program(code) of drawing picture and graph in Applet.  Hi Friend, Please visit the following links: http://www.roseindia.net/java/example/java
Java gui program for drawing rectangle and circle
Java gui program for drawing rectangle and circle   how to write java gui program for drawing rectangle and circle? there shoud be circle and rectangle button, check box for bold and italic, and radio button red,green and blue
drawing triange using stars - Java Beginners
drawing triange using stars  How do i Write a program to draw the boundaries of a plot of land with the structure shown in the diagram, for any set of input values for the dimensions. Use ?*? to represent the sides   
How to create LineDraw In Java
will learn how to create Line Drawing. This program  implements a line Drawing component. A java program explains the stroke line i.e. how to make thick..., define a class named, LineDraw in program for creating a java AWT Line Drawing
importing excel file and drawing multiple graphs from one excel file
importing excel file and drawing multiple graphs from one excel file  thanks a lot sir for replying with code for importing excel file... index in the line HSSFCell cell1 = row.getCell(a); i want to pass column ID..how
Draw Line
Draw Line  sir i want to draw a moving line in j2me.That line should also show arrow in moving direction. How can we do so
line graph
line graph  I have developed an application and in that i have to compare 2 reports using line graph from the data taken from ms access database?please help
on line exam
on line exam  how we can upload the data on the server from any site
nio read file line by line
nio read file line by line  Is there any way to read file line by line using the Java nio package? How to use the nio classes to read file line by line? Thanks   Hi, The easiest way to read file line by line is to use
Simple Line Canvas Example
Simple Line Canvas Example       This is a simple example of drawing lines using canvas class in J2ME. In this example we are creating three different lines at different
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid  drawing rectangle in java/Creating a draw rectangle (filled with black color) function in Java for a grid
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full DescriptionADS_TO_REPLACE_1
objective c read file line by line
objective c read file line by line  Please explain how to read files in Objective C line by line
Java read file line by line
Java read file line by line In this section, you will learn how to read a file line by line. Java has provide several classes for file manipulation. Here we are going to read a file line by line. For reading text from a file it's better
Java - How to read a string line per line
Java - How to read a string line per line  Java - How to read a string line per line I am trying to find the tutorial for reading the String line per line. I have a String data, which contains many lines. What is the best way
Java write to file line by line
Java write to file line by line In this section, you will learn how to write a file line by line. It is better to use Writer class instead of OutputStream... to a byte array. The method newLine() is used for writing a new line character. We
java - read file line by line in Java
java - read file line by line in Java  Hi, how one can read a text file line by line in Java? What is the benefits of reading a file line by line... file in Java can be read line by line with the help of BufferedReader class
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... to Read a file line by line using BufferedReader, efficiently and using less memory... java.io.BufferedReader in your program and use the class for reading the file line
Command line arguments
Command line arguments  Please explain me what is the use of "command line arguments" and why we need to use
Line From code
Line From code  document.getElementById("demo").innerHTML=Date(); Please explain each and every word in this line
ModuleNotFoundError: No module named 'line'
ModuleNotFoundError: No module named 'line'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'line' How to remove the ModuleNotFoundError: No module named 'line' error
Line Breaks in PHP
Line Breaks in PHP  Hi, I am beginner in PHP language. How to do the line-break in PHP? Does somebody help me in this regard. Thanks
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart
sorting Line in c
sorting Line in c  Hi I need help with sorting line in programming c asking user to enter 1-10 characters and then sort them in lower case, alphabetical and ascending order. Any help will be appreciated! please help! void
divide the line in to two
divide the line in to two  In| this |example |we| are| creating |an |string| object| .We| initialize| this| string |object| as| "Rajesh Kumar"|.| We| are| taking| sub| string | In above mentioned line based on the tag i want
Java Command Line Input
Java Command Line Input  How to get input from command line in java ?   Hi please Find the code for inputting data from the command line System.out.println("Please Input A Number"); BufferedReader br
character as command line arguments
character as command line arguments  public class testing { public static void main(String args[]) { char a; a=args[0]; System.out.println("character is:"+a); } } what will be the above program output
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source selected from listbox and multiple targets selected from checkboxes. After submitting... multiple target. And each line should have dynamically link of other jsp page
java line chart
java line chart  Hi, I want to draw a graphic in java line chart and ? searched the documents ?n the web. I found the example codes ?n your site (http://www.roseindia.net/chartgraphs/xyline-chart.shtml) and tr?ed ?n my
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
dead line tomorrow...help
dead line tomorrow...help  1)write a program to convert double to int and viceversa using rmi(remote method invocation) 2)write a program to download a video file and run it on your client machine using rmi 3)fibonacci

Ads