Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT Line Drawing

Have Programming Question? Ask it here!
 
 
 


P.Umesh Reddy
Line Drawing
1 Answer(s)      6 years and 3 months ago
Posted in : Swing AWT



Advertisement
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.... The setStroke() method sets the settings of the strokes of line used when drawing... Different Line Styles     
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
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
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 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.
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
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
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
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
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... named, LineDraw in program for creating a java AWT Line Drawing component
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   
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
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full Description
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
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
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 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
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
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
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
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
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
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
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line In this tutorial I will explain you how you can read big file line by line... is very useful in reading big file line by line in Java. In this tutorial we
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 Number Reader Example
Line Number Reader Example      ...; readLine() method is used to read the data line by line. LineNumberReader class is provide getLineNumber() method to get the number of line. We
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
COMMAND LINE ARGUMENTS
COMMAND LINE ARGUMENTS  JAVA PROGRAM TO ACCEPT 5 COMMAND LINE ARGUMENTS AND FIND THE SUM OF THAT FIVE.ALSO FIND OUT LARGEST AMONG THAT 5   Hi Friend, Try the following code: import java.util.*; class
JBoss Unix and Line Separator
JBoss Unix and Line Separator  Hi, I am trying to solve an critical problem. I have an application which write a batch file using the method println from the PrintWriter class from java api, this method uses the default line
Compiling package in command line
Compiling package in command line  Hi friends, i am totally new to java programming, i am basic learner in java. My query is, How to compile java package using command line. For Eg: When i compile following command, c:>set
What is wrong with this line
What is wrong with this line  What is wrong with this line JOptionPane.showMessageDialog(null? for Using Lewandowski's Savings pgrm!"); from if (input.equals("exit") || input.equals("Exit")) { JOptionPane.showMessageDialog
Java Read File Line by Line - Java Tutorial
Java Read File Line by Line - Example code of reading the text file in Java one line at a time     ... to write java program to read file line by line. We will use the DataInputStream
On line examination project
On line examination project  Hi, I am doing project in jsp,nam eis online examination project. I am facing some problems. In my database several questions. There should be one question in one page. And 2 button previous and next
Advertisements
 

 

 

DMCA.com